gpt4 book ai didi

r - 如何创建 "nested"条形图?

转载 作者:行者123 更新时间:2023-12-04 11:51:45 25 4
gpt4 key购买 nike

this blog post中的最后一张图片.

我试过搜索“嵌套条形图”和“分层条形图”,但它们可能不是这个词。

最佳答案

使用 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()

enter image description here

关于r - 如何创建 "nested"条形图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8047152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com