Dear all I am trying to represent a dependent variable (treatment) against different independent variables (v1, v2, v3....v20). I am using the following command: boxplot(v1~treatment,data=y, main="xxxxxx",xlab="xxxxxx", ylab="xxxxxx") However, it provides me only one graph for v1~treatment. For the other comparisons, I have to repeat the same command but changing the parameters. My intentions is to get different plots in just one sheet using only one command. Is it possible to join the same order for all the comparisons in only one command? Thanks David [[alternative HTML version deleted]]
On Oct 5, 2012, at 9:01 AM, David Gramaje wrote:> > > Dear all > > I am trying to represent a dependent variable (treatment) against different independent variables (v1, v2, v3....v20). I am using the following command: > > > However, it provides me only one graph for v1~treatment. For the other comparisons, I have to repeat the same command but changing the parameters. My intentions is to get different plots in just one sheet using only one command. Is it possible to join the same order for all the comparisons in only one command? >Two options: A) Melt the dataframe with reshape2::melt then use boxplot( value ~ interaction(variable,treatment) ) B) Melt the dataframe Use bwplot in lattice with a slightly more full featured formula interface bwplot(value~cat|variable, data=amelt) Option B is more beautiful in my opinion. -------------- next part -------------- A non-text attachment was scrubbed... Name: Rplot.pdf Type: application/pdf Size: 84789 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121005/85a6f90d/attachment-0002.pdf> -------------- next part -------------- -- David Winsemius, MD Alameda, CA, USA
Hello, I've once written a function that does more or less what you want, but it has no formula interface. # Input: # x - matrix or data.frame of numeric vectors to graph # by - a factor or coercible to factor multi.boxplot <- function(x, by, col=0, ...){ x <- as.data.frame(x) uniq.by <- unique(by) by <- factor(by) len <- length(uniq.by) - 1 n <- ncol(x) n1 <- n + 1 col <- rep(col, n)[seq_len(n)] boxplot(x[[ 1 ]] ~ by, at = 0:len*n1 + 1, xlim = c(0, (len + 1)*n1), ylim = range(unlist(x)), xaxt = "n", col=col[1], ...) for(i in seq_len(n)[-1]) boxplot(x[[i]] ~ by, at = 0:len*n1 + i, xaxt = "n", add = TRUE, col=col[i], ...) axis(1, at = 0:len*n1 + n1/2, labels = uniq.by, tick = TRUE) } a <- matrix(data=runif(300,max=2), nrow=100, ncol=3) fac <- sample(letters[1:4], 100, TRUE) multi.boxplot(a, fac) Hope this helps, Rui Barradas Em 05-10-2012 17:01, David Gramaje escreveu:> > Dear all > > I am trying to represent a dependent variable (treatment) against different independent variables (v1, v2, v3....v20). I am using the following command: > > boxplot(v1~treatment,data=y, main="xxxxxx",xlab="xxxxxx", ylab="xxxxxx") > > However, it provides me only one graph for v1~treatment. For the other comparisons, I have to repeat the same command but changing the parameters. My intentions is to get different plots in just one sheet using only one command. Is it possible to join the same order for all the comparisons in only one command? > > Thanks > David > > [[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.
Does something like this make any sense? library(reshape2) library(ggplot2) yy <- structure(list(A = c(23, 21, 21, 20, 19, 19), B = c(20, 18, 20, 19, 20, 18), C = c(15, 15, 15, 12, 13, 13)), .Names = c("A", "B", "C"), class = "data.frame", row.names = c(NA, -6L)) y1 <- melt(yy) # using reshape2 ggplot(y1, aes(variable, value))+ geom_boxplot() # or ggplot(y1, aes(variable, value))+ geom_boxplot() + facet_grid(variable ~ .) John Kane Kingston ON Canada> -----Original Message----- > From: dagrape at hotmail.com > Sent: Fri, 5 Oct 2012 18:01:39 +0200 > To: r-help at r-project.org > Subject: [R] Multiple graphs > boxplot > > > > Dear all > > I am trying to represent a dependent variable (treatment) against > different independent variables (v1, v2, v3....v20). I am using the > following command: > > boxplot(v1~treatment,data=y, main="xxxxxx",xlab="xxxxxx", ylab="xxxxxx") > > However, it provides me only one graph for v1~treatment. For the other > comparisons, I have to repeat the same command but changing the > parameters. My intentions is to get different plots in just one sheet > using only one command. Is it possible to join the same order for all the > comparisons in only one command? > > Thanks > David > > [[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!