我有一个包含大约 30000 个集群和 10 个因素的两列数据集,如下所示:
cluster-1 Factor1
cluster-1 Factor2
...
cluster-2 Factor2
cluster-2 Factor3
...
我想代表集群集中因素的共现。类似于“1234 个集群中的因子 1+因子 3+因子 5”,等等不同的组合。我以为我可以像饼图这样的东西,但有 10 个因素,我认为可能有太多组合。
什么是表示这一点的好方法?
最佳答案
这里有一个很好的编程问题需要解决:
如何计算不同聚类中因素的共现次数?
首先模拟一些数据:
n = 1000
set.seed(12345)
n.clusters = 100
clusters = rep(1:n.clusters, length.out=n)
n.factors = 10
factors = round(rnorm(n, n.factors/2, n.factors/5))
factors[factors > n.factors] = n.factors
factors[factors < 1] = 1
data = data.frame(cluster=clusters, factor=factors)
> data
cluster factor
1 1 6
2 2 6
3 3 5
4 4 4
5 5 6
6 6 1
...
然后这里是可用于将每个因素组合在集群中出现的次数制表的代码:
counts = with(data, table(tapply(factor, cluster, function(x) paste(as.character(sort(unique(x))), collapse=''))))
这可以表示为一个简单的饼图,例如,
dev.new(width=5, height=5)
pie(counts[counts>1])
但是像这样的简单计数通常最有效地显示为排序表。有关更多信息,请查看 Edward Tufte .
关于r - r 中大约 10 个因子在集群中的共存饼图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7952761/