R中有两个类别的堆叠的小号
我正在尝试在R中创建一个堆叠的Barplot,以可视化两组的差异。
我的数据集看起来像这样:
用户 | 我希望user |
---|---|
ABC | 男性 |
DEF | 女性 |
ghi | 女性 |
XYZ | 女性 |
JKL | 男性 |
ABC | 男性 |
XYZ | 男性XYZ |
XYZ | 女性, |
在X轴上,计数或百分比<< Y轴上的代码> a ,a
的类别是堆栈,填充或不同的组。
编辑:
ggplot(data, aes(x=User, fill = A)) +
geom_bar(position = "fill") +
scale_fill_brewer(palette = "BrBG") +
labs(y = "Percent")
有没有办法显示堆栈上的百分位标签?
I am trying to create a stacked barplot in R to visualize differences in two groups.
My dataset looks like this:
A | User |
---|---|
ABC | Male |
DEF | Female |
GHI | Female |
XYZ | Female |
JKL | Male |
ABC | Male |
XYZ | Male |
XYZ | Female |
I would like the User
to be on the x-axis, the count or percentage of A
on the y-axis, and the categories of A
to be the stacks or the fill or the different groups.
Edit:
ggplot(data, aes(x=User, fill = A)) +
geom_bar(position = "fill") +
scale_fill_brewer(palette = "BrBG") +
labs(y = "Percent")
Is there a way to show the percent labels on the stacks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以先计算百分比,然后使用这些值在
geom_text
中添加为标签。输出
You can calculate percentage first, then use those values to add as labels in
geom_text
.Output
Data
您可以尝试
You may try