Re: [R] supplying dynamic main argument to plot?

From: Francisco J. Zagmutt <>
Date: Wed 28 Jun 2006 - 07:01:05 EST

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=" "))   Sys.sleep(1)

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" <>
>To: "Afshartous, David" <>,
>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]]
> mailing list
>PLEASE do read the posting guide!
> mailing list PLEASE do read the posting guide! Received on Wed Jun 28 07:13:35 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 28 Jun 2006 - 08:14:27 EST.

Mailing list information is available at Please read the posting guide before posting to the list.