【问题标题】:Delete or hide the data points' labels删除或隐藏数据点的标签
【发布时间】:2019-12-30 18:20:10
【问题描述】:

我有下面的数据框:

Val1<-c(0.5,0.7,0.8,0.9)
Val2<-c(0.5,0.7,0.8,0.9)
Val3<-c(0.5,0.7,0.8,0.9)
Val4<-c(0.5,0.7,0.8,0.9)
vales<-data.frame(Val1,Val2,Val3,Val4)
row.names(vales)<-c("asd","dasd","dfsdf","fdff")

我正确处理以创建集群散点图:

library(tidyverse)  # data manipulation
library(cluster)    # clustering algorithms
library(factoextra) # clustering algorithms & visualization
library(plotly)

cl<-scale(vales)
dist <- get_dist(cl)
k2 <- kmeans(cl, centers = 2, nstart = 25)

cl %>%
  as_tibble() %>%
  mutate(cluster = k2$cluster,
         state = row.names(vales))

p2<-fviz_cluster(k2, data = cl)
p2+geom_text(aes(label=""))

#or
ggplotly(p2+geom_text(aes(label="")))

我想删除点的标签,但我不明白为什么它们会出现,而在下面的情况下却没有。

df <- USArrests
df <- na.omit(df)

df <- scale(df)
distance <- get_dist(df)

k2 <- kmeans(df, centers = 2, nstart = 25)
df %>%
  as_tibble() %>%
  mutate(cluster = k2$cluster,
         state = row.names(USArrests))

p1 <- fviz_cluster(k2, geom = "point", data = df) + ggtitle("k = 2")
p1+geom_text(aes(label=""))


#or
ggplotly(p1+geom_text(aes(label="")))

【问题讨论】:

    标签: r ggplot2 ggplotly factoextra


    【解决方案1】:

    默认情况下,fviz_cluster 的 geom 参数是 geom=c("point","text")。通过指定geom="point",不显示标签(geom="text" 只显示标签)。

    fviz_cluster(k2, data = cl, geom="point")
    

    【讨论】:

    • 我同意这一点。那么,您不需要使用:ggplotly(p2+geom_text(aes(label="")))。 ggplotly(p2) 足够你想要的了。
    猜你喜欢
    • 2015-03-25
    • 1970-01-01
    • 1970-01-01
    • 2020-03-22
    • 2016-08-30
    • 1970-01-01
    • 2014-09-23
    • 2021-04-18
    • 2020-02-16
    相关资源
    最近更新 更多