Reputation: 2572
I currently have a plot that I would like to save with certain resolution values. I am using the pdf()
function in R
with:
pdf("my_plot.pdf", height=5, width=10)
plot(....)
dev.off()
From this, I get a pdf which when I use Mac's Info in Finder, it gets:
I am wondering how I can set the height
and width
parameters in pdf()
to obtain match a certain resolution above, such as 811 x 478. Thanks.
Upvotes: 1
Views: 2200
Reputation: 263411
If height is 811 and width is 478 pixels (although I later decided those were probably reversed) then you could divide those by a typical dpi to get a height and width in inches which is the unit that the pdf
device expects:
pdf("my_plot.pdf", height=811/300, width=478/300)
plot(....)
dev.off()
I'm wondering, however, whether the first number is a height or width? I suspect you may be seeing width as the first value. Let's look at the help page:
?pdf
And look at some examples with Finder and Preview:
I'm looking at small pdf files and seeing that an icon is reported to have a resolution of 128 × 128 in Finder.app and Preview reports that it is 1.78 × 1.78 inches, so it probably was created as a 72 dpi document. The pdf() help page says that pointsize
can be used to affect that parameter and defaults to 12
to specify 1/72 inches.
So perhaps you will want:
pdf("my_plot.pdf", width=811/72, height=478/72)
Upvotes: 4