在R中绘制堆积的条形图

编程入门 行业动态 更新时间:2024-10-28 09:18:03
本文介绍了在R中绘制堆积的条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想用以下数据在R中创建直方图[堆积条形图]:

I would like to create histogram [stacked bar plot] in R with data like this:

Period = c(1,1,2,2,3,3,4,4) Sample = c("A","B","A","B","A","B","A","B") Value1 = c(3,2,6,7,3,2,1,2) Value2 = c(1,0,5,2,2,0,2,5) x <- data.frame(Period,Sample,Value1,Value2)

是否可能在X轴上具有句点"和样本",以及在堆叠条形图"中的值("Value1"和"Value2").因此,第一个直方图的最高值将为4(值1和值2分开) 提前谢谢你的帮助! 最好的问候.

Is it possible to have "Period" and "Sample" on the X axes and The values ("Value1" and "Value2") in "Stacked Bar Plot". So the hight of first histogram would be 4 (separate for Value1 and Value2) Thank you for your help in advance! Best regards.

推荐答案

它不像ggplot解决方案那么漂亮,但

It's not as pretty as the ggplot solution but

v <- rbind(Value1,Value2) barplot(v,beside=FALSE,names=levels(interaction(Period,Sample)),legend=TRUE)

似乎可以正常工作.

更多推荐

在R中绘制堆积的条形图

本文发布于:2023-07-18 00:44:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1139217.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条形图

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!