I am trying to create an EPS file at a particular size (for public paper publication) with ggplot2 and the postscript device from grDevices.
The problem is that when I use the code below the bounding Box is completely wrong and instead of adapting the size of the paper to the size I have set grDevices draws it on a A4 paper.
I don't know what I am missing here.
library(ggplot2)
library(grDevices)
dat <- data.frame(cond = rep(c("A", "B"), each=10),
xvar = 1:20 + rnorm(20,sd=3),
yvar = 1:20 + rnorm(20,sd=3))
g<-ggplot(dat,aes(x=xvar, y=yvar )) +
geom_point(aes(x=xvar, y=yvar ))
g
setEPS(paper="special",width = 6.75,height = 2.79,horizontal = FALSE, onefile = FALSE)
postscript(file ="Test.eps")
print(g)
dev.off()
EPS files don't have a media size, that's one of the requirements for an EPS.
EPS files declare the BoundingBox of the marks made by the EPS program and the enclosing document should alter the CTM at the point the EPS is included in the enclosing PostScript program so that the EPS is scaled to cover the desired area of the media.
So you can't actually "adapt the size of the media" with an EPS program, and the BoundingBox is probably not incorrect (the fact that it doesn't match your intention doesn't make it wrong)
If you send an EPS to a PostScript interpreter it may (if you are lucky) draw it on the default media. It may instead give you a blank page, because EPS files are not permitted to use the 'showpage' operator either!
If you use Ghostscript to interpret the EPS program you can use -dEPSCrop to set the media to the BoundingBox of the EPS. I'm not certain but its possible that if you set -dFitPage, then Ghostscript will rescale the EPS to fit the current media size. If you want a media size other than the default (A4 or Letter) you will have to specify the -dDEFAULTPAPERSIZE first, or use one of the controls to set the media size (eg -g or -dMEDIAWIDTHPOINTS/MEDIAHEIGHTPOINTS)
If you want the EPS drawn on a media size other then the BoundingBox, its probably easiest to write a PostScript program to set the media size, set the CTM to position and scale the EPS, then include the EPS, and finally use showpage to transfer the rendered content to the output media.