Re: [R] ggplot2: setting global graphic parameters with png driver

From: Xavier Chardon <>
Date: Tue, 29 Apr 2008 18:30:51 +0200

Sorry I forgot these informations. I'm using R 2.70, under Linux (Debian Etch). The png driver uses cairo, and the version of libcairo installed is 1.2.4 (which is not the latest, but more recent versions are not available is the debian stable repositories)

I tried bitmap(), and it does not look good, because there is no antialiasing.

I tried a lot of different settings with png(). Setting the size in inches and the resolution did not help. pointsize does help, but seems limited: increasing pointsize does not do anything after a certain value. It's like there's a maximum font size in pixels that I can achieve. Does that make any sense?
This size is barely OK if I want an image of 1024x1024 pixels, which should be OK.

However, there is still the problem of line width, wich are not affected by "pointsize". Of course, I can modify the linewidth directly for every plot, but it would be easier with a global setting of ggplot ?

Many thanks,


Prof Brian Ripley a écrit :
> You forgot to mention your version of R and your platform (and R has
> at least 3 separate png() devices).
> In 2.7.0, specify the size in inches and increase the resolution.
> In earlier versions, try bitmap(). From NEWS for 2.7.0
> o Considerable efforts have been made to make the default output
> from graphics devices as similar as possible (and in
> particular close to that from postscript/pdf). Many devices
> were misinterpreting 'pointsize' in some way, for example as
> being in device units (pixels) rather than in points.
> On Tue, 29 Apr 2008, Xavier Chardon wrote:
>> Hi all,
>> I prepared a few charts with ggplot2, and was happy with the results
>> as displayed on screen.
>> I tried to draw them with a PNG driver instead. But I ran into
>> several problems while trying to increase the resolution of the picture.
>> Mainly, when I increased the picture size (e.g png(width=1024,
>> height=768) ), the texts (title, labels, etc...) where too small. I
>> tried to set the "pointsize" option of the driver. That did the
>> trick, to some extent. But it seems limited, and I couldn't get big
>> enough fonts for high resolution images. Also, I tried the
>> "resolution" setting of the driver. But this has an effect on lots of
>> things, e.g. the length of the lines in the legend, so I gave up this
>> idea.
>> I tried to change the font size of all elements, with e.g.
>> grid.gedit("label", gp=gpar(cex=4) ). But the position of the labels
>> does not change then, and with the bigger font, they are drawn on top
>> of the axis or of its title.
>> Another problem was that the line width is also too small in big
>> images. I couldn't find a way to change it globally.
>> So, is there a way to go easily from a plot that looks good on screen
>> (X11 driver) to a similar png image? Or is it possible to change the
>> default settings of ggplot2 (line size and font size in particular,
>> which are not covered by the ggopt function) ? I guess people usually
>> export their charts as image files, so hopefully there's an easy
>> solution.
>> Many thanks,
>> Xavier
>> ______________________________________________
>> mailing list
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.

Xavier Chardon
Thésard Institut de l'élevage / INRA
Projet ACTA "modélisation environnementale des systèmes bovins et porcins"
02 23 48 50 91

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 29 Apr 2008 - 19:31:11 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 Tue 29 Apr 2008 - 20:30:44 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive