【发布时间】:2020-04-12 23:37:26
【问题描述】:
我想创建一个直方图,显示每个年龄组(x 轴)的女性比例(y 轴)。我想为每个年龄组设置两个条形图,分别代表患有“N”病和未患“N”病的女性。
数据:
我查看过的与该主题相关的其他帖子:
r percentage by bin in histogram ggplot
Barplots with multiple factor groupings and mean of variable across those factors
我尝试过的代码:
ggplot(N_group, aes(x=Age_2, fill=Sex))+
geom_bar(aes( y=..count../tapply(..count.., ..x.. ,sum)[..x..]), position="dodge" ) +
geom_text(aes( y=..count../tapply(..count.., ..x.. ,sum)[..x..],
label=scales::percent(..count../tapply(..count.., ..x.. ,sum)[..x..]) ),
stat="count", position=position_dodge(0.9), vjust=-0.5)
这比较了患有“N”病的男性和女性。
【问题讨论】:
-
你看过这个post。原因,问的 Q 是不可重现的。请不要发布数据截图。
标签: r ggplot2 histogram geom-bar