[R] Help

John Kane jrkrideau at inbox.com
Fri Jun 29 18:29:16 CEST 2012


I think I may understand what you want.

I 'd say the first thing to do is to combine the 3 matrices into a single data frame with a column for the values of A, B C 

Here is a mock-up with something like what I mean. I just used two columns of data for the mock-up.

Then, you can reshape the data using melt() from the reshape2 package and then graph the data using ggplot from the ggplot2 package.

Is this something like what you want?
=============================================================

library(ggplot2)
library(reshape2)

A  <-  data.frame( m = (rep("A", 10)) , b=rnorm(10), c = rnorm(10))
B  <-  data.frame( m = (rep("B", 10)) , b=rnorm(10), c = rnorm(10))
C  <-  data.frame( m = (rep("C", 10)) , b=rnorm(10), c = rnorm(10))

mydata  <-  rbind( A, B, C )
names(mydata)  <-  c( "group", "k1", "k2" )
mdata  <-  melt(mydata)

p  <-  ggplot( mdata , aes(variable, value , colour = variable )) + geom_boxplot() +
           facet_grid( group ~ .)
p

==============================================================

John Kane
Kingston ON Canada


> -----Original Message-----
> From: hannah.hlx at gmail.com
> Sent: Thu, 28 Jun 2012 16:29:54 -0400
> To: r-help at r-project.org
> Subject: [R] Help
> 
> Dear all,
>   I need some help on plotting multiple boxplots on one figure.
>   I have three matrix A, B and C. Each of them is a 1000 by 10 matrix.
> The 10 columns of all three matrix correspond to the
> 10 values of the same parameter, say k=1, ..., 10.
>   I want to make a plot where x axis represents different values of k.
> For each k value, I want to plot three boxplots, one on top of another.
> For example, for k=1, I want to draw three boxplot based on the first
> column of A, B and C respectively. Similarly, I do the same for the rest
> of
> k values.
>   Can some one give me some hint on this?
>   Thank you so much.
>         Hannah
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!



More information about the R-help mailing list