ggsave png font size

4,361 views
Skip to first unread message

learnr

unread,
Mar 10, 2009, 9:59:06 AM3/10/09
to ggplot2
Dear all

I am trying to save ggplot2 plots on the disk using the ggsave(*.png)
function.

Unfortunately the output is unusuable, as the font sizes of labels
have been reduced significantly, and the height/width of the resulting
png file is roughly 4.375 times of the file produced with png().
At the same time ggsave(*.pdf) is working just fine.

Below is the code I was using to test the functionality.

Regards
Learnr.

library(ggplot2)

set.seed(213)
df <- data.frame (a=sample(10), b=sample(10))
p <- qplot (data=df, a,b)

p
ggsave("ggpng.png", width=7, height=7)
ggsave("ggpdf.pdf", width=7, height=7)

png("png.png")
p
dev.off()

pdf("pdf.pdf")
p
dev.off()

hadley wickham

unread,
Mar 10, 2009, 10:12:01 AM3/10/09
to learnr, ggplot2
You probably want ggsave(..., dpi = 72)

Hadley
--
http://had.co.nz/

David Lovell

unread,
Mar 11, 2009, 6:30:17 PM3/11/09
to ggplot2
I've also found it useful to save a png via Adobe Acrobat to avoid the
"what you see is not quite what you get" issue.
Cheers,
David

James Howison

unread,
Mar 13, 2009, 3:47:41 PM3/13/09
to ggplot2
I've also found that a good way to do these things is to figure out
the actual size of the final piece, then make sure to set the font
size to the font size you want in place.

eg. If your paper/site is in 9 pt type, setup the theme with:

theme_set(theme_gray(base_size=9))

Then save the plot to the actual height and width you want (in inches
or pixels) using ggsave(). That helps avoid situations of poor
fontsize balance due to scaling down (eg by includegraphics in latex).

Tangental, I know :)

--J
Reply all
Reply to author
Forward
0 new messages