pointsize in png graphics
Hi
Jan.Kleinn at partnerre.com wrote:
Dear all,
I'm trying to produce 2 png files, one consisting of an image plot and a
color-table (also an image plot) and the other one consisting of 4 image
plots and a color table. I'd like the color table to be exactly the same.
The way I proceded is the following:
for one plot and the color-table
png(file = png.file, width = 650, height = 800, pointsize = 16)
layout(matrix(c(1, 2), ncol = 2, nrow = 1, byrow = T),
widths = c(6, 1), heights = 1)
par(mar = c(0.2, 0.2, 0.2, 0.2), mgp = c(2, 1, 0), las = 0)
...
dev.off()
for 4 plots and the color-table
png(file = png.file, width = 650, height = 800, pointsize = 16)
layout(matrix(c(1, 2, 5, 3, 4, 5), ncol = 3, nrow = 2, byrow = T),
widths = c(3, 3, 1), heights = c(1, 1))
par(mar = c(0.2, 0.2, 0.2, 0.2), mgp = c(2, 1, 0), las = 0)
...
dev.off()
The only difference is the layout of the plot. The outcome though is
completely different. It seems that the definition of the size of one point
is different in the two plots as the graphics with 4 plots and color table
has smaller fonts and smaller margins. What do I have to do to be sure the
size of the fonts is the same in two different png graphcis of exactly the
same size when the pointsize is the same?
I'm working with Windows XP and tried both running the R script as a batch
job and running it within Emacs with ESS.
I think the problem is that R is trying to think for you. R
automatically reduces text size when there are more than three plots (or
more than three cells in a layout) on a page. Below are two suggestions
for making the two layouts the same:
# dummy image plot
dummyplot <- function(col) {
plot.new()
usr <- par("usr")
rect(usr[1], usr[3], usr[2], usr[4], col=col)
}
# original problem
x11()
layout(matrix(c(1, 2), ncol = 2, nrow = 1, byrow = T),
widths = c(6, 1), heights = 1)
par(mar = c(0.2, 0.2, 0.2, 0.2), mgp = c(2, 1, 0), las = 0)
dummyplot("orange")
dummyplot("blue")
x11()
layout(matrix(c(1, 2, 5, 3, 4, 5), ncol = 3, nrow = 2, byrow = T),
widths = c(3, 3, 1), heights = c(1, 1))
par(mar = c(0.2, 0.2, 0.2, 0.2), mgp = c(2, 1, 0), las = 0)
dummyplot("red")
dummyplot("yellow")
dummyplot("pink")
dummyplot("violet")
dummyplot("blue")
# solution 1: make second layout same as first
# leave first page alone
# revert auto cex decrease on second page
x11()
layout(matrix(c(1, 2), ncol = 2, nrow = 1, byrow = T),
widths = c(6, 1), heights = 1)
par(mar = c(0.2, 0.2, 0.2, 0.2), mgp = c(2, 1, 0), las = 0)
dummyplot("orange")
dummyplot("blue")
x11()
layout(matrix(c(1, 2, 5, 3, 4, 5), ncol = 3, nrow = 2, byrow = T),
widths = c(3, 3, 1), heights = c(1, 1))
par(mar = c(0.2, 0.2, 0.2, 0.2), mgp = c(2, 1, 0), las = 0,
### CHANGES HERE
cex=1.5, mex=0.66)
dummyplot("red")
dummyplot("yellow")
dummyplot("pink")
dummyplot("violet")
dummyplot("blue")
# solution 2: make first layout same as second
# make same number of columns/rows in first layout
# leave second page alone
x11()
layout(### CHANGES HERE
matrix(c(1, 1, 2, 1, 1, 2), ncol = 3, nrow = 2, byrow = T),
widths = c(6, 1), heights = 1)
par(mar = c(0.2, 0.2, 0.2, 0.2), mgp = c(2, 1, 0), las = 0)
dummyplot("orange")
dummyplot("blue")
x11()
layout(matrix(c(1, 2, 5, 3, 4, 5), ncol = 3, nrow = 2, byrow = T),
widths = c(3, 3, 1), heights = c(1, 1))
par(mar = c(0.2, 0.2, 0.2, 0.2), mgp = c(2, 1, 0), las = 0)
dummyplot("red")
dummyplot("yellow")
dummyplot("pink")
dummyplot("violet")
dummyplot("blue")
Paul
Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/