[R] ggsave to .png bug in ggplot2 (?)

Dieter Menne dieter.menne at menne-biomed.de
Thu Aug 20 09:12:34 CEST 2009

Chris Friedl wrote:
> Text is really small and legend boxes are huge in this plot when saved to
> .png with ggsave. Plot is correct (i.e. looks the same as the screen) when
> saved with dev.print. Saving to .pdf with ggsave give the correct output.

You are not alone. Things like this always happen the day before the
deadline, when you want to make minor changes. It is not limited to ggplot,
but looking at the variant

x <- data.frame(value=rnorm(5000, mean=0), case="A")
y <- data.frame(value=rnorm(5000, mean=3), case="B")
xy <- rbind(x, y)
p <- ggplot(xy, aes(x=value, colour=case, group=case)) + geom_density()
ggsave(p, width=4,height=4,filename = "xy_ggsave.png")

makes me believe that this function should be banned. You might also check
the output of the ggsave documentation page to learn what scaling means in
R. (Slightly modified below). 

ratings <- qplot(rating, data=movies, geom="histogram")
qplot(length, data=movies, geom="histogram")
ggsave(ratings, file="ratingsA.pdf")
ggsave(ratings, file="ratingsB.pdf", width=4, height=4)
# make twice as big as on screen
ggsave(ratings, file="ratingsC.pdf", scale=2)

I never use these functions in final production, be it in standard graphics
or lattice, but always open a device and close it after all plots have been


View this message in context: http://www.nabble.com/ggsave-to-.png-bug-in-ggplot2-%28-%29-tp25055170p25057074.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list