我有一个两列的数据集,大约有30000个聚类和10个因素,如下所示:
cluster-1 Factor1
cluster-1 Factor2
...
cluster-2 Factor2
cluster-2 Factor3
...我想要表示聚类集中的因素的共现。类似于“1234集群中的Factor1+Factor3+Factor5”,以此类推表示不同的组合。我认为我可以像饼图一样,但有10个因素,我认为可能有太多的组合。
什么是表示这一点的好方法?
发布于 2011-11-01 02:15:45
这里有一个很好的编程问题需要解决:
如何计算不同集群中因子的共现数量?
首先模拟一些数据:
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。
https://stackoverflow.com/questions/7952761
复制相似问题