[R] supplying dynamic main argument to plot?

Francisco J. Zagmutt gerifalte28 at hotmail.com
Tue Jun 27 23:01:05 CEST 2006

Hi Dave,

Try using paste within main i.e.

k=sample(1:10,10, replace=T)

for(i in k){
  plot(x,y, xlab="gamma", ylab="r1", main=paste("Patient", i, sep=" "))

In this eaxmple I am just plotting the same x,y values on each figure but 
you can easily plot the observations for each patient by subetting your data 
by the K variable. See ?"[" for more details on subsetting.

I hope this helps


Dr. Francisco J. Zagmutt
College of Veterinary Medicine and Biomedical Sciences
Colorado State University

>From: "Afshartous, David" <afshart at exchange.sba.miami.edu>
>To: "Afshartous, David" <afshart at exchange.sba.miami.edu>,        
><r-help at stat.math.ethz.ch>
>Subject: [R] supplying dynamic main argument to plot?
>Date: Tue, 27 Jun 2006 16:19:12 -0400
>Simple question but I don't seem to be able to find the answer in the
>When using "plot" within a loop, is there any way to supply the argument
>to "main" dynamically,
>i.e., so that the title is Patient k below as the loop cycles through
>each value of k?
>plot(x,y, xlim=c(0,250), ylim=c(0,1000), xlab="gamma", ylab="r1",
>main="Patient k")
>ps - I'm running windows.
>	[[alternative HTML version deleted]]
>R-help at stat.math.ethz.ch mailing list
>PLEASE do read the posting guide! 

More information about the R-help mailing list