如何组织变量在x轴barplotR(复制) - How to group variables on x axis barplot in R [duplicate]

- 此内容更新于:2016-02-24
主题:

这个问题已经有了一个答案:分组条形图使用barplot【复制】1回答我想阴谋这个数据帧。我寻找一个类似的例子,我不能找到一个精确匹配。我想要一个barplot整个数据帧,所以每个蜱虫在x轴上(wx,y,z)将有四个值(a,b,c,d)。

原文:

This question already has an answer here:

I would like to plot this data frame. I have searched for a similar example and I couldn't find an exact match.

x <- data.frame(a=c(1:4), 
                b=c(5:8),
                c=c(9:12),
                d=c(13:16))
row.names(x) <- c("w","x","y","z")

I want one barplot for the whole data frame, so each tick on the x-axis (w,x,y,z) will have four values (a,b,c,d).

网友:你寻找的东西叫做barplot分组。

(原文:What you are looking for is called a grouped barplot.)

解决方案:

enter image description here

原文:
x <- data.frame(a=c(1:4), 
                b=c(5:8),
                c=c(9:12),
                d=c(13:16))

x = as.matrix(x)
row.names(x) <- c("w","x","y","z")
x = t(x)

barplot(x,beside=T, ylim=c(0,20), legend.text=rownames(x),  args.legend = c(ncol=4))

enter image description here