Hi, Suppose I have a for() loop that draws 6 boxplots as follows: par(mfrow = c(2, 3)) for(i in 2:length(spam.sample)) { boxplot(split(spam.sample[,i], yesno)) } Where spam.sample is a data frame with 7 columns, and I'm interested in plotting column 2 ~ 7 against column 1 (yesno). The boxplots appeared fine, however I'm trying to add a meaningful title, x and y labels to them. Is it possible to do this in the loop? Cheers, Kevin ------------------------------------------------------------------------------ Ko-Kang Kevin Wang Postgraduate PGDipSci Student Department of Statistics University of Auckland New Zealand Homepage: http://www.stat.auckland.ac.nz/~kwan022 E-mail: kwan022 at stat.auckland.ac.nz -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Ko-Kang Kevin Wang wrote:> > Hi, > > Suppose I have a for() loop that draws 6 boxplots as follows: > par(mfrow = c(2, 3)) > for(i in 2:length(spam.sample)) { > boxplot(split(spam.sample[,i], yesno)) > } > > Where spam.sample is a data frame with 7 columns, and I'm interested in > plotting column 2 ~ 7 against column 1 (yesno). > > The boxplots appeared fine, however I'm trying to add a meaningful title, > x and y labels to them. Is it possible to do this in the loop?Yes. Why not? Some obvious solutions: a) With a vector of names, let's call it main.labels: boxplot(..., main = main.labels[i]) b) To take the name of the data in your call: boxplot(..., main = deparse(substitute(spam.sample[,i], list(i=i)))) c) Or the column name of the plotted column: boxplot(..., main = colnames(spam.sample)[i]) Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear Kevin, You could try something like: names=colnames(spam.sample) titles=LETTERS[1:6] par(mfrow = c(2, 3)) for(i in 2:length(spam.sample)) { boxplot(split(spam.sample[,i], yesno), xlab=names[1], ylab=names[i], main=titles[i-1]) } Of course, the titles would be replaced with meaningful text. Is that what you want? John At 05:54 PM 5/25/2002 +1200, Ko-Kang Kevin Wang wrote:>Suppose I have a for() loop that draws 6 boxplots as follows: > par(mfrow = c(2, 3)) > for(i in 2:length(spam.sample)) { > boxplot(split(spam.sample[,i], yesno)) > } > >Where spam.sample is a data frame with 7 columns, and I'm interested in >plotting column 2 ~ 7 against column 1 (yesno). > >The boxplots appeared fine, however I'm trying to add a meaningful title, >x and y labels to them. Is it possible to do this in the loop?----------------------------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: jfox at mcmaster.ca phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox ----------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._