[R] getting a title in a plot during an lapply

Peter Alspach PAlspach at hortresearch.co.nz
Thu Nov 16 22:56:58 CET 2006


Mark

> In my code below tempa and tempb are numeric vectors that I
> combined into a dataframe along with the deciles of tempa.
> I have an lapply statement that goes through the dataframe
> and does ten plots according to the appropriate decile.
> The code is below and it works fine. There are no bugs so I
> figure there was no need to include structure statements on the data.
> Also, I don't want to use coplot because the axes get sort of
> messed up because of outliers.
>
> tempa.deciles<-cut(tempa,breaks=quantile(tempa,probs=seq(0,1,0
> .1)),inclu
> de.lowest=TRUE)
> df<-data.frame(tempa,tempb,tempa.deciles)
> levels(df$tempa.deciles)<-paste("Decile ",1:10,sep="")
> lapply(split(df, df$tempa.deciles), function(x) {
> print(cor(x$tempa,x$tempb)); plot(x$tempa,x$tempb);
>
> I would like to include a title on each plot so that I can
> recognize which plot goes with which decile but I don't know
> how to do that basically because I can't figure out what
> lapply is looping over by number. I definitely looked around
> in various R books but I was not successful. Thanks for your help.

Try

plot(x$tempa, x$tempb, main=x$tempa.deciles[1])

Peter Alspach

______________________________________________________

The contents of this e-mail are privileged and/or confidenti...{{dropped}}



More information about the R-help mailing list