英文:
Stacked Barplot in R-Studio
问题
我正在尝试使用barplot()函数在R中构建一个堆叠的条形图。
我有一些数据如下:
counts1 = table(questions$first)
counts1
0 1
29 81
counts2 = table(questions$snd)
counts2
0 1
40 48
我想要将它们作为堆叠的条形图呈现,但我得到的是:
barplot(c(counts1, counts2), main="BarPlot",
col=c("darkblue", "red"), horiz=TRUE)
是否有可能在这里获得两个堆叠的条形图?我尝试了很多但没有找到一个好的解决方案(我对R相当新,不想使用更高级别的绘图库如ggplot)。此外,是否可以获得相对频率而不是绝对计数值?
提前感谢。
英文:
I am trying to build up a stacked barplot in R using barplot().
I have some Data given like :
counts1= table(questions$first)
counts1
0 1 #output
29 81
counts2 = table(questions$snd)
counts2
0 1
40 48
And I would like to have that as an stacked barplot, but what I get is :
barplot(c(counts1,counts2), main="BarPlot",
col=c("darkblue","red"),horiz = TRUE)
is it somehow possible to get 2 stacked bars here? I have tried a lot but I did not come up with a good solution. (I am quite new to R and dont want to use higher level plots like ggplots). And furthermore is it possible to get the relative frequency instead of absolut count values?
Thanks in Advance.
答案1
得分: 1
代码部分不需要翻译。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论