gpt4 book ai didi

r - 删除或隐藏数据点的标签

转载 作者:行者123 更新时间:2023-12-04 01:40:28 25 4
gpt4 key购买 nike

我有下面的数据框:

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")

关于r - 删除或隐藏数据点的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57659922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com