Sébastien Bihorel
2011-Feb-15 21:50 UTC
[R] Relationships between png resolution, axis.text$cex trellis setting, and paddings
Dear R-users, I was wondering if somebody could shed some light on the relationships existing between the resolution of a png device, the axis.text$cex trellis setting, and the paddings of the actual graph. In the following code, I create a custom trellis theme that set (among other thing) axis.text$cex to 1 instead of the default 0.8. Then a lattice graph is created and exported to three png devices using three different resolutions. You should notice that the spacing between the axis labels and tick labels decreases at high resolution. This is not the case if axis.text$cex is kept at 0.8. I have tried to scale various trellis settings related to padding but that did not seem to help. Any idea on how to compensate the change in axis.text$cex would be welcome. Sebastien require(lattice) my.theme <- function() { cur.settings <- standard.theme() theme <- list( background=list(col='transparent'), layout.widths=list(left.padding=0.5, ylab.axis.padding=0, right.padding=0), layout.heights=list(top.padding =0, main.key.padding =0, axis.xlab.padding=0, key.sub.padding =0, bottom.padding =0.5), axis.text=list(cex=1), axis.components=list(top=list(tck=0, pad1=0, pad2=0), right=list(tck=0, pad1=0, pad2=0))) inter.theme <- modifyList(cur.settings, theme) return(inter.theme) } df <- data.frame(x=-10:10,y=rnorm(21)) myplot <- xyplot(y~x,data=df, xlab="Whatever",ylab="Random") png(file='padding_test_normal_125.png', width=750, height=750, res=125) trellis.par.set(my.theme()) print(myplot, split=c(1,1,2,2), more=TRUE,newpage=TRUE) print(myplot, split=c(1,2,2,2), more=TRUE,newpage=FALSE) print(myplot, split=c(2,1,2,2), more=TRUE,newpage=FALSE) print(myplot, split=c(2,2,2,2), more=FALSE,newpage=FALSE) dev.off() png(file='padding_test_normal_150.png', width=900, height=900, res=150) trellis.par.set(my.theme()) print(myplot, split=c(1,1,2,2), more=TRUE,newpage=TRUE) print(myplot, split=c(1,2,2,2), more=TRUE,newpage=FALSE) print(myplot, split=c(2,1,2,2), more=TRUE,newpage=FALSE) print(myplot, split=c(2,2,2,2), more=FALSE,newpage=FALSE) dev.off() png(file='padding_test_normal_300.png', width=1800, height=1800, res=300) trellis.par.set(my.theme()) print(myplot, split=c(1,1,2,2), more=TRUE,newpage=TRUE) print(myplot, split=c(1,2,2,2), more=TRUE,newpage=FALSE) print(myplot, split=c(2,1,2,2), more=TRUE,newpage=FALSE) print(myplot, split=c(2,2,2,2), more=FALSE,newpage=FALSE) dev.off() [[alternative HTML version deleted]]