[R] trellis.graphic in for-loop
Martina Pavlicova
pavlicov at stat.ohio-state.edu
Fri Apr 4 21:38:32 CEST 2003
HI,
try to use 'print.trellis()'
Martina
-----------------------------
see:
library(lattice)
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]
print.trellis(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)
}
--------------------------------------------------------------------------
Department of Statistics Office Phone: (614) 292-1567
1958 Neil Avenue, 304E Cockins Hall FAX: (614) 292-2096
The Ohio State University E-mail: pavlicov at stat.ohio-state.edu
Columbus, OH 43210-1247 www.stat.ohio-state.edu/~pavlicov
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