从 data.frame 创建条形图 [英] Create barplot from data.frame
本文介绍了从 data.frame 创建条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 R 中,我有一个 data.frame,就像图片顶部的那个.
In R I have a data.frame like the one on the top of the picture.
是否有可能创建如下所示的条形图?
Is there a possibility to create a barplot like below?
数据框:
X1 X2 X3
--- ---- ---- ----
A 2 3 4
B 4 2 1
C 1 NA NA
条形图:
----------------------------
| |
| # # |
| # # # |
| # # # # # |
| # # # # # # # |
----------------------------
X1 X2 X3 X1 X2 X3 x1
A B C
推荐答案
使用基本图形,您可以简单地做到这一点:
Using base graphics you can do this simply:
mydf <- data.frame( X1=c(A=2, B=4, C=1), X2=c(3,2,NA), X3=c(4,1,NA) )
barplot(t(as.matrix(mydf)), beside=TRUE)
使用对 axis
的额外调用可以使标签更像问题中.
Using additional calls to axis
can give the labeling more like in the question.
这篇关于从 data.frame 创建条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文