Take the 2-minute tour ×

I got following data frame (simplified here):

    H2475  H2481  H2669  H2843  H2872  H2873  H2881  H2909
E1 24.470 26.481 15.120 18.490 16.189 11.422 14.886 18.512
E2  1.016  0.363  0.509  1.190  1.855  0.958  0.771  0.815
E3  0.671  0.637  0.571  0.447  0.116  0.452  0.403  0.753
E4  3.448  2.826  2.183  2.607  4.288  2.526  2.820  3.523
E5  2.548  1.916  1.126  1.553  1.089  1.228  0.887  1.065

where E1 - E5 are row numbers. I would like to create a boxplot (or even better violin plot) for the values of each row. I want to ignore column IDs, and have row IDs as "factors".

Something like this top answer: How to generate boxplot

but with E1 - E5 as values. As you may guess I am new to melt/cast/reshape.

Thank you very much for your help

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

You had thought through the problem 95% of the way there. You were just missing that you needed to create a column out of the row.names(). Something like this should work assuming your data is stored in a data.frame named dat

dat$group <- row.names(dat)
dat.m <- melt(dat, id.vars = "group")
ggplot(dat.m, aes(group, value)) + geom_boxplot()

enter image description here

share|improve this answer
Thank you very much. It works, and I have learned few more things ;-) –  darked89 Dec 14 '11 at 20:27
add comment

Although you have already accepted the answer from @Chase, I show you a more simply way:

share|improve this answer
add comment

Your Answer


