堆积条形图在R [英] Stacked Bar Plot in R
本文介绍了堆积条形图在R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经看过关于R中堆积条形图的类似问题,但我仍然没有任何运气。
I've looked at the similar questions on here regarding stacked bar plots in R, but I'm still not having any luck.
我创建了以下数据框:
I have created the following data frame:
A B C D E F G
1 480 780 431 295 670 360 190
2 720 350 377 255 340 615 345
3 460 480 179 560 60 735 1260
4 220 240 876 789 820 100 75
A:G代表x轴,y轴代表持续时间(秒)。
我会如何在R中堆叠以下数据?
A:G represents the x-axis and the y-axis would be duration (seconds). How would I go about stacking the following data in R?
非常感谢您的宝贵时间和帮助。
Thank you very much in advance for your time and help.
推荐答案
数据集:
The dataset:
dat <- read.table(text = "A B C D E F G
1 480 780 431 295 670 360 190
2 720 350 377 255 340 615 345
3 460 480 179 560 60 735 1260
4 220 240 876 789 820 100 75", header = TRUE)
现在您可以将数据框转换为矩阵并使用 barplot
函数。
Now you can convert the data frame into a matrix and use the barplot
function.
barplot(as.matrix(dat))
这篇关于堆积条形图在R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文