删除或隐藏数据点的标签

时间:2019-08-26 14:30:54

标签: r ggplot2 ggplotly

我的数据框如下:

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

1 个答案:

答案 0 :(得分:2)

默认情况下,<input name="boxesnumbers" value="5 3 1"> <a href="#" >3</a> <a href="#" >5</a> <a href="#" >1</a> <script> $('a').click(function() { $('[name="boxesnumbers"]').val($('[name="boxesnumbers"]').val().replace($(this).text(), '')) }); </script> 的{​​{1}}自变量为from imblearn.over_sampling import ADASYN ada = ADASYN() # X is feature set and y is the label X_resampled, y_resampled = ada.fit_sample(X, y) # Add X_resampled, y_resampled into one dataframe 。通过指定geom,不会显示标签(fviz_cluster仅显示标签)。

geom=c("point","text")