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

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


Hi Dave,

Try using paste within main i.e.

x=rnorm(100)
y=runif(100)
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

Francisco

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

>From: "Afshartous, David" <afshart@exchange.sba.miami.edu>
>To: "Afshartous, David" <afshart@exchange.sba.miami.edu>,
><r-help@stat.math.ethz.ch>
>Subject: [R] supplying dynamic main argument to plot?
>Date: Tue, 27 Jun 2006 16:19:12 -0400
>
>All,
>
>Simple question but I don't seem to be able to find the answer in the
>documentation:
>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")
>
>
>thanks
>dave
>ps - I'm running windows.
>
>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help@stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide!
>http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html 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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.