r - 删除或隐藏数据点的标签
问题描述
我有下面的数据框:
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="")))
解决方案
默认情况下, 的geom
参数fviz_cluster
是geom=c("point","text")
。通过指定geom="point"
,不显示标签(geom="text"
只显示标签)。
fviz_cluster(k2, data = cl, geom="point")
推荐阅读
- javascript - 如何将Javascript变量传递给PHP函数
- git - 使用 gerrit/git 命令行检测 gerrit 补丁是否需要变基?
- javascript - 如何测试一个点是否在 SVG 封闭路径内
- php - 如何插入两个表的 ID(多对多关系)
- angular - “ngbd-modal-component”不是已知元素
- hibernate - Hibernate Search - recreate index if existing data was not indexed before
- excel - VBA中两个日期之间的间隔
- java - 在 Hyperledger Fabric 上创建通道时,由于超时发送事务失败
- android - 如何读取数组内数组内的JSON数组
- javascript - 在 FabricJS 中,如何通过在鼠标点击的坐标处重叠的一组对象进行识别?