Ellis, David
2011-Apr-15 14:20 UTC
[R] boxplot with 2 treatments and 2 variables (with 2 corresponding y-axes)
Hi, I am a complete newcomer to R and although I can plot standard box-plots I am struggling with this... I have two treatments - A & B, and 2 variables 1 & 2. I want to compare boxplots of variable 1 with variable 2 for each treatment. I would also like them to all be on the same graphic. I would like treatment to be on the x axis (A and B) and above A and B have their corresponding boxplots for both variables.I would also like 2 seperate y-axes, one for each variable - Variable 1 has a continuous y axis, and variable 2 is a percentage (of variable 1 in-fact, not that this should make a difference). It would also be helpful if the boxplots were a different colour for each variable and that this corresponded somehow to the relevant axis. Or if someone can think of another way to show which treatment each boxplot is that would be gratefully recieved Hope this makes sense and isn't too much of a pain to answer! Thanks in advance Dave [[alternative HTML version deleted]]
Uwe Ligges
2011-Apr-17 17:39 UTC
[R] boxplot with 2 treatments and 2 variables (with 2 corresponding y-axes)
On 15.04.2011 16:20, Ellis, David wrote:> Hi, > > I am a complete newcomer to R and although I can plot standard box-plots I am struggling with this... > > I have two treatments - A& B, and 2 variables 1& 2. I want to compare boxplots of variable 1 with variable 2 for each treatment. I would also like them to all be on the same graphic. > > I would like treatment to be on the x axis (A and B) and above A and B have their corresponding boxplots for both variables.I would also like 2 seperate y-axes, one for each variable - Variable 1 has a continuous y axis, and variable 2 is a percentage (of variable 1 in-fact, not that this should make a difference). > > It would also be helpful if the boxplots were a different colour for each variable and that this corresponded somehow to the relevant axis. Or if someone can think of another way to show which treatment each boxplot is that would be gratefully recieved > > Hope this makes sense and isn't too much of a pain to answer!Not sure if it makes sense: If you have two boxplots beside each other, you tend to compare them directly. If they are unrelated (different variables with different scaling as in this case), I'd be careful not to confuse the reader of the plot .... Best, Uwe Ligges> Thanks in advance > Dave > > > [[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.
Petr PIKAL
2011-Apr-18 06:29 UTC
[R] Odp: boxplot with 2 treatments and 2 variables (with 2 corresponding y-axes)
Hi r-help-bounces at r-project.org napsal dne 15.04.2011 16:20:23:> Hi, > > I am a complete newcomer to R and although I can plot standard box-plotsI am> struggling with this... > > I have two treatments - A & B, and 2 variables 1 & 2. I want to compare > boxplots of variable 1 with variable 2 for each treatment. I would alsolike> them to all be on the same graphic. > > I would like treatment to be on the x axis (A and B) and above A and Bhave> their corresponding boxplots for both variables.I would also like 2seperate> y-axes, one for each variable - Variable 1 has a continuous y axis, and > variable 2 is a percentage (of variable 1 in-fact, not that this shouldmake a> difference). > > It would also be helpful if the boxplots were a different colour foreach> variable and that this corresponded somehow to the relevant axis. Or if > someone can think of another way to show which treatment each boxplot isthat> would be gratefully recieved >Here is one option x<-rnorm(10) y<-rnorm(10)+5 trt<-sample(letters[1:2], 10, replace=T) df<-cbind(c(x,y), rep(trt,2), rep(c("v1","v2"), each=10)) df<-as.data.frame(df) df[,1]<-as.numeric(as.character(df[,1])) boxplot(split(df[,1], interaction(df[,2], df[,3]))) however you have only one y axis. Similar result but better structured you can get using ggplot2 or lattice packages. Having 2 y axes is rather confusing but you can scale your values and add axis annotation with axis(....) but I doubt it is worth an effort. Regards Petr> Hope this makes sense and isn't too much of a pain to answer! > > Thanks in advance > Dave > > > [[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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.