在R中绘制堆积的条形图 [英] plot stacked bar plot in R

查看:122
本文介绍了在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中绘制堆积的条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆