# Help

10 messages
Open this post in threaded view
|
Report Content as Inappropriate

## 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]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Help

 Hi It seems to me that it can be done by ggplot2 package. However I do not understand what is three boxplots one on top of another? How could you see the bottom boxplot when it is twice overplotted? library(ggplot2) p <- ggplot(mtcars, aes(factor(cyl), mpg)) p + geom_boxplot(aes(fill = factor(vs))) Regards Petr > > 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]] > > ______________________________________________ > [hidden email] 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. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Help

 Here are two possibilities depending on what you mean by "on top" of one another: > A <- matrix(rnorm(1000), ncol=10) > B <- matrix(rnorm(1000), ncol=10) > C <- matrix(rnorm(1000), ncol=10) > oldpar <- par(mfrow=c(3,1), mar=c(3, 3, 2, 2)) > boxplot(A) > boxplot(B) > boxplot(C) > par(oldpar) Or really "on top" using color and changing the size of the boxes to make them visible. > boxplot(A) > boxplot(B, border="red", boxwex=.7, add=TRUE) > boxplot(C, border="blue", boxwex=.6, add=TRUE) ---------------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352 > -----Original Message----- > From: [hidden email] [mailto:r-help-bounces@r- > project.org] On Behalf Of Petr PIKAL > Sent: Friday, June 29, 2012 3:30 AM > To: li li > Cc: r-help > Subject: Re: [R] Help > > Hi > > It seems to me that it can be done by ggplot2 package. However I do not > understand what is three boxplots one on top of another? How could you > see > the bottom boxplot when it is twice overplotted? > > library(ggplot2) > p <- ggplot(mtcars, aes(factor(cyl), mpg)) > p + geom_boxplot(aes(fill = factor(vs))) > > Regards > Petr > > > > > > 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]] > > > > ______________________________________________ > > [hidden email] 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. > > ______________________________________________ > [hidden email] 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. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Help

 In reply to this post by li li-13 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: [hidden email] > Sent: Thu, 28 Jun 2012 16:29:54 -0400 > To: [hidden email] > 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]] > > ______________________________________________ > [hidden email] 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! ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Help

 Hi Petr, David and John,   Thanks for the reply. I am sorry that I did not make it very clear. "One on top of another" may not be the right expression. Actually what I wanted is the second option of David's. There are 10 columns in the plot and, in each column, there are three boxplots. Different colors can be used to distinguish the three boxplots in the same column.     John, when I run the code, I got the message below: Error in rq.fit.br(x, y, tau = tau, ...) : Singular design matrix In addition: Warning message: In is.na(rows) : is.na() applied to non-(list or vector) of type 'NULL' Thanks again, everyone.       Hannah 2012/6/29 John Kane <[hidden email]> > 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: [hidden email] > > Sent: Thu, 28 Jun 2012 16:29:54 -0400 > > To: [hidden email] > > 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]] > > > > ______________________________________________ > > [hidden email] 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! > > >         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Help

Open this post in threaded view
|
Report Content as Inappropriate

## Re: Help

 On 2012-06-30 07:04, John Kane wrote: > >     Hi Hannah, >     I have run both the original code and the code copied from the email and >     both seem to work just fine. >     I don't know why you are getting that error message.   Do you have both >     ggplot2 and reshape2 loaded?  Still that should not give you the error >     message you are getting. In fact given the data I supplied, I just don't >     understand what it is trying to say. >     I cannot even find a function [1]rq.fit.br. [...] This function is in the quantreg *package*. So Hannah isn't telling us the whole story. Peter Ehlers ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Help

Open this post in threaded view
|
Report Content as Inappropriate