Re: [R] Lines to plots with a for-loop

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Tue, 05 Jun 2007 14:04:12 +0200

Saanisto, Taija wrote:
> Hello all,
>
> I'm plotting several graphs with a for-loop with a code:
>
> par(mfrow=c(3,4))
>
> for(i in levels(fHCGB$code)) with(subset(fHCGB,code==i),
> plot(pooledPlateIntra, type="b", ylim=ylim, xlab=code, ylab="CV%"))
>
>
> With which I have no problems.. However I need to add lines to all of
> these 12 plots, but I cannot get it to work. I've tried for example
>
> par(mfrow=c(3,4))
>
> for(i in levels(fHCGB$code)) with(subset(fHCGB,code==i),
> plot(pooledPlateIntra, type="b", ylim=ylim, xlab=code, ylab="CV%")
> points(fHCGB$limitVarC,type="b", col="green")))
>
> But run into errors. How can the lines be added?
>
The with() construct gets a little more complicated if you want to do more than one thing inside:

for(i in levels(fHCGB$code)) with(subset(fHCGB,code==i), {   plot(pooledPlateIntra, type="b", ylim=ylim, xlab=code, ylab="CV%")   points(fHCGB$limitVarC,type="b", col="green") })

or, since with() is really only needed for the plot()

for(i in levels(fHCGB$code)) {
  with(subset(fHCGB,code==i),

     plot(pooledPlateIntra, type="b", ylim=ylim, xlab=code, ylab="CV%"))   points(fHCGB$limitVarC,type="b", col="green") }

(& you might have used lines() rather than points() if you think of it as an added line, but that's a matter of taste since the two functions only differ in the default for type=.)

    -p

> Taija Saanisto
> Biostatistician
> Quality assurance, Process Development
> PerkinElmer Life and Analytical Sciences / Wallac Oy
> Phone: +358-2-2678 741
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_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
> and provide commented, minimal, self-contained, reproducible code.
>



R-help_at_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 and provide commented, minimal, self-contained, reproducible code. Received on Tue 05 Jun 2007 - 12:07:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 05 Jun 2007 - 12:31:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.