[R] Ploting in for() loop

John Fox jfox at mcmaster.ca
Sat May 25 13:13:05 CEST 2002


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list