[R] List dimention labels to plots of components

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Aug 20 09:50:36 CEST 2004


White, Charles E WRAIR-Wash DC wrote:

> It is frustrating to see the labels I want in the dimensions of a list but not be able to extract those labels into titles for plots generated from component objects. If someone could set me straight, I would appreciate it. For your amusement, I have provided an example of the Byzantine code I am currently using to avoid loops:

The code below works perfectly. I don't get the point what you are 
looking for ....

Uwe Ligges


> # Simulate ANOVA type test data
> sex<-c(rep(1,8),rep(0,8))
> dose<-c(rep(1,4),rep(0,4))
> treatment<-c(rep(1,2),rep(0,2))
> fix<-sex+dose+treatment
> Response<-fix+rnorm(16)
> Sex<-rep("Male",16)
> Sex[sex==0]<-"Female"
> Dose<-rep("High",16)
> Dose[dose==0]<-"Low"
> Treatment<-rep("A",16)
> Treatment[treatment==0]<-"B"
> dat<-data.frame(Sex,Dose,Treatment,fix,Response)
> 
> # Redundant Transfer and Execution of Dimension ID?
> mymod<-function(x){
>   model<-lm(Response~Sex,data=x)
>   list(model,Dose=x$Dose[1],Treatment=x$Treatment[1])}
> myplt<-function(x){
>   plot(x[[1]],main=paste(x$Dose,"/",x$Treatment,sep=""))}
> 
> # Generate list of Model Estimates 
> dat.lm<-by(dat,list(Dose=dat$Dose,Treatment=dat$Treatment),mymod)
> 
> # Execute plots with labels
> pdf(file="junk.pdf",height=7.5,width=10)
> par(mfrow=c(2,2))
> bitbucket<-lapply(dat.lm,myplt)
> dev.off()
> 
> Charles E. White, Senior Biostatistician, MS
> Walter Reed Army Institute of Research
> 503 Robert Grant Ave., Room 1w102
> Silver Spring, MD 20910-1557
> 301 319-9781
> Personal/Professional Site: http://users.starpower.net/cwhite571/professional/
> 
> ______________________________________________
> 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




More information about the R-help mailing list