[R] trellis.graphic in for-loop

Roger Peng rpeng at stat.ucla.edu
Fri Apr 4 21:03:52 CEST 2003


Trellis graphics need to be print()-ed for them to show on the device.  I
think if you wrap your call to barchart() with print(), it should work as
you expect.

-roger
_______________________________
UCLA Department of Statistics
rpeng at stat.ucla.edu
http://www.stat.ucla.edu/~rpeng

On Fri, 4 Apr 2003, Alexander.Herr at csiro.au wrote:

> Hi list,
> 
> I am unsuccessfully trying to produce a serious of trellis barcharts from
> within a for-loop. The barcharts work outside the loop. What am I missing?
> Example attached.
> 
> Thanks Herry
> 
> #XXXXXXXXXXXXXXXXXXXXXX
> 
> 
> trellis.device(bg="white")
> trellis.par.get("fontsize")->fontsize
> fontsize$default<-16
> trellis.par.set("fontsize",fontsize)
> 
> a<-c(1,2,4,5,4,3,3,3)
> b<-c(2,5,1,1,1,3,3,3)
> c<-c(3,5,1,2,2,5,5,5)
> as.data.frame(cbind(a,b,c))->q21
> varnames<-colnames(q21)
> i<-9999
> for (i in 1:3) {
> round(table(q21[,i])/sum(table(q21[,i])),3)*100->z1
>  as.data.frame.table(table(q21[,i]))->z1
>   round(z1[,2]/sum(z1[,2]),3)*100->z1[,2]
>    colnames(z1)<-c(varnames[i],"y")
>    xnames<-levels(z1[,1])
>     paste(xnames[1]," - low",sep="")->xnames[1]
>      paste(xnames[length(xnames)]," - high",sep="")->xnames[length(xnames)]
>   z1[,1]<-xnames
>  as.factor(z1[,1])->z1[,1]
> barchart(
>   horizontal=FALSE,
>    z1[,2]~z1[,1],
>     ylab=list("% frequency",cex=1.5),
>      main=list(varnames[i],cex=1.25),
>     scales=list(1,cex=1.5), col="#ffd18f",
>    sub=list("Rating",cex=1.25)
>         )
> filename<-paste("test",i,"_q21k.jpg",sep="")
> #dev.print(jpeg, filename , width=1000, height=1000, quality=100,
> bg="white", pointsize=20)
> }
> 
> 
> 	[[alternate HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>



More information about the R-help mailing list