在R语言中使用单列的Barplot集群

时间:2015-05-24 11:35:10

标签: r

是否有算法来创建像这样的分层条形图?

http://www.axiis.org/examples/HClusterColumnExample.html

相关问题: 2-layer barplot in R

1 个答案:

答案 0 :(得分:1)

当然,有办法做到这一点。但那将是非常不标准的。但是,对barplot的充分理解将为您带来很长的路要走:

# Create some toy data
set.seed(1)
n <- 100
df <- data.frame(F1 = sample(c("A", "B"), n, replace = TRUE), 
                 F2 = sample(c("c", "d"), n, replace = TRUE))
tab <- t(table(df))

# Create plot
barplot(colSums(tab), width = 2, space = 0.5)
barplot(tab, beside = TRUE, add = TRUE, col = rainbow(2), axisnames = TRUE)
legend("top", col = rainbow(2), pch = 15, legend = rownames(tab))

Imgur