1

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).

Sergio.pv
  • 1,380
  • 4
  • 14
  • 23
  • 1
    What you are looking for is called a [grouped barplot](http://www.google.se/search?q=grouped+barplot+in+r). – Backlin May 23 '14 at 14:08

1 Answers1

2
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

Andre Silva
  • 4,782
  • 9
  • 52
  • 65