根据 R 中的聚类分析创建气泡图(或类似的东西)

问题描述 投票:0回答:1

以下数据框是聚类分析结果的示例,我想创建可视化效果。我正在考虑一个考虑列总数的气泡图,但它还应该打印 var1 的值。不知道如何做到这一点,不幸的是我无法添加预期的结果(基本上是因为我不确定我在寻找什么;-)。所以基本上,对于每个集群,我想要一个随变量 Total 缩放的气泡,并且该气泡还应该包含 var1 中的值。

set.seed(1)
df <- data.frame(cluster = rep(1:3,5),
                  var1 = sample(rep(LETTERS[1:10]),15,replace =TRUE),
                  total = sample(30:300,15, replace=TRUE))
r ggplot2 cluster-analysis
1个回答
0
投票

Plotly 是一个使图形具有交互性的好工具。 Plotly 允许您将鼠标悬停在点上并显示文本,而不是将文本写入难以阅读的气泡中。尝试类似的事情

library(ggplot2)
library(plotly)

set.seed(1)
df <- data.frame(cluster = rep(1:3,5),
                  var1 = sample(rep(LETTERS[1:10]),15,replace =TRUE),
                  total = sample(30:300,15, replace=TRUE))

plt <- ggplot(df, aes(x=cluster, y=var1, size = total, text=paste('</br>var1: ',var1,'</br>total: ',total, '</br>1: ',1))) +
    geom_point(alpha=0.7)

ggplotly(plt)
© www.soinside.com 2019 - 2024. All rights reserved.