[R] png() and pdf() alignment problems

From: Roland Kaiser <roland.kaiser_at_sbg.ac.at>
Date: Fri, 1 Feb 2008 00:19:03 +0100


Hi all!

My aim is to print a thematic map containing vector output and an image backdrop (six orthophoto tiles). The size of one image tile is 2500 rows and 2500 columns. The are six tiles to be printed.

Of course this is far to much for sending the job to a pdf() device. The raster image would consist of 37500000 squares, each representing a raster cell.

So my a attempt was to separate vector and image output, and overlay it afterwards.

Doing so I found that png() and pdf() do not register corectly.

The following script shows that a custom device size (not square) can be responsible for the missing preccesion.

require(grDevices)

x <- y <- seq(-4*pi, 4*pi, len=27)
r <- sqrt(outer(x^2, y^2, "+"))
z <- cos(r^2)*exp(-r/6), col=gray((0:32)/32)

# example1
# standard device size

pdf("pdf_fit.pdf")
image(z)
dev.off()
png("png_fit.png", res = 96)
image(z)
dev.off()

# both files overlay with high precision
# as known from R grtaphics output
# see attached example example1.pdf

# example2
# custom device size

pdf("pdf.pdf", width = 8, height = 4)
image(z)
dev.off()
png("png.png", width = 8, height = 4, units = "in", res = 96) image(z)
dev.off()

# png output is somewhat larger
# and aligning them is a bit nasty
# see attached example example2.pdf

I attached the two files
showing the overlay of the examples above.

Is there anything I'm missing?

Thanks for any advice,

Roland



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Received on Fri 01 Feb 2008 - 11:45:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 01 Feb 2008 - 12:30:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive