[R] ggplot2: font size mismatch for pdf output
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue May 13 10:29:34 CEST 2008
If I do
> windows(width=6, height=5)
then the pdf plot is very good copy of what I see on screen. So the main
issue seems to be that you changed the device size when you asked for the
save. If you do that, you need to change 'pointsize' too -- but as you
changed the aspect ratio, you cannot make that work exactly.
There is a bug in ggsave() for bitmap devices: it computes the width and
height from 'dpi', but it fails to pass that information on to the
devices, which assume 72dpi. So what it actually asked for was a
8 x 6.67 inch plot at 72dpi. 72dpi would be a better default, as not all
of the many bitmap devices work correctly at other resolutions (and none
did prior to R 2.7.0).
If you want an accurate png copy of what you see on screen, use savePlot()
or the device menus. That copies the backing bitmap.
On Mon, 12 May 2008, Michael Friendly wrote:
> Sorry for not providing this in my initial posting.
> I'm using R version 2.7.0 (2008-04-22), on Win XP Pro.
>
> As I said, the .png output matched what I saw on screen.
> It was the .pdf output for which the font size was noticeably
> larger, enough to make the legend run off the screen.
>
> -Michael
>
> Prof Brian Ripley wrote:
>> What version of R and OS is this? Prior to R 2.7.0 there was little
>> attempt to match output dimensions from various devices, and one of the png
>> devices in 2.7.0 has an error in doing so, fixed in R-patched (see NEWS).
>>
>> On Mon, 12 May 2008, Michael Friendly wrote:
>>
>>> Hi
>>>
>>> In the following, the graph I see on the screen and the .png output
>>> coincide. However, in the .pdf file, the fonts seem to be scaled
>>> fairly larger, resulting in the label for the top legend disappearing.
>>> Is this an infelicity or bug, or is there something I've missed?
>>>
>>> More generally, how do I control the size of fonts used in legends
>>> and axis labels?
>>>
>>> library(car)
>>> library(ggplot2)
>>>
>>> qp <-qplot (education , income , shape=type , size=women , colour=prestige
>>> ,
>>> xlab="Education" , ylab="Income", data=Prestige)
>>> + scale_y_continuous(limits=c(NA, 20000))
>>
>> Hmm, you can't break the line before '+'.
>>
>>> qp + scale_size(to=c(1,8))
>>>
>>> ggsave(file="prestige-ggplot.png", width=6, height=5) # OK
>>> ggsave(file="prestige-ggplot.pdf", width=6, height=5) # fonts too large
>>
>> I would not expect you to be able to specify a smaller size without also
>> reducing 'pointsize'. E.g. dev.print() does so, but ggsave seems not to.
>>
>>> -Michael
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list