是否有一种简单的方法可以用R制作水平的单堆堆积的Barplot?
如果有人可以帮助我与R一起制作单个堆叠的Barplot,我将不胜感激。这是我使用的数据的一个小例子:
cell_type Percentage
CD20 B cells 15.00
CD4 T cells 25.00
Other cells 60.00
这是我使用的内容,但不能对其进行过多修改。
p1 <- ggplot(Data, aes(x = "", y = percentage, fill = cell_type))
p1
p2 <- p1 + geom_col()
p2
非常感谢您的帮助。
I'd appreciate it if anyone could help me with making a single stacked Barplot with R. Here is a small example of data to plot:
cell_type Percentage
CD20 B cells 15.00
CD4 T cells 25.00
Other cells 60.00
This is what I used, but cannot modify it too much.
p1 <- ggplot(Data, aes(x = "", y = percentage, fill = cell_type))
p1
p2 <- p1 + geom_col()
p2
Many thanks in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
coord_flip
使其水平调整栏厚度指定width
参数,并且可以使用scape_fill_manual
手动设置填充颜色:如果您有然后,您需要设置X轴变量。
Use
coord_flip
to make it horizontal, to adjust bar thickness specify thewidth
argument, and you can set fill colors manually usingscale_fill_manual
:If you have multiple bars then you will need to set an x-axis variable.
也许您想要这样的东西:
输出:
Maybe you want something like this:
Output:
更新:
X-axis:
第一个答案:
这是 base r barplot :作为替代方法:
Update:
x-axis:
First answer:
Here is a base R barplot: as an alternative approach: