R 你如何创建一个;嵌套的;条形图?
中的最后一个图像R 你如何创建一个;嵌套的;条形图?,r,graph,R,Graph,中的最后一个图像 我尝试搜索“嵌套条形图”和“层次条形图”,但它们可能不是它的对应词。使用ggplot并创建单独的层: library(ggplot2) set.seed(1) stupid <- data.frame( group= LETTERS[1:5], men = sample(1:10, 5), women = sample(1:10, 5) ) # Melt the data and calculate totals mstupid <-
我尝试搜索“嵌套条形图”和“层次条形图”,但它们可能不是它的对应词。使用
ggplot
并创建单独的层:
library(ggplot2)
set.seed(1)
stupid <- data.frame(
group= LETTERS[1:5],
men = sample(1:10, 5),
women = sample(1:10, 5)
)
# Melt the data and calculate totals
mstupid <- melt(stupid, id.vars="group")
stupidTotal <- ddply(mstupid, .(group), summarize, value=sum(value))
ggplot() +
geom_bar(data=stupidTotal, aes(x=group, y=value), fill="grey50") +
geom_bar(data=mstupid, aes(x=group, y=value, fill=variable),
stat="identity", position="dodge") +
theme_bw()
库(ggplot2)
种子(1)
愚蠢的在软件包中查找“barNest”plotrix
使用以下方法:
ggplot() +
geom_bar(data=stupidTotal, aes(x=group, y=value, fill="grey50"), stat="identity") +
geom_bar(data=mstupid, aes(x=group, y=value, fill=variable),
stat="identity", position="dodge") +
theme_bw()