Can not save plot to png file correctly

809 views
Skip to first unread message

Peng Yu

unread,
May 31, 2010, 3:20:12 PM5/31/10
to ggplot2
library(ggplot2)

data=data.frame(
X=sample(10,1000,replace=T)
, Y=letters[1:10]
)

p=qplot(X, data=data, geom='histogram') + facet_wrap( ~ Y)
save(p, file='error.png')

The above qplot work properly if I don't plot it to a file. But if I
plot it to a png file, the png file is always corrupted. Would you
please let me know what is wrong?

--
Regards,
Peng

error.png

Felipe Carrillo

unread,
May 31, 2010, 3:34:21 PM5/31/10
to Peng Yu, ggplot2, r-h...@stat.math.ethz.ch
You can save as png like this too:

library(ggplot2)
data=data.frame(
  X=sample(10,1000,replace=T)
  , Y=letters[1:10])

png("mypng.png")


qplot(X, data=data, geom='histogram') + facet_wrap( ~ Y)

dev.off()
 
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA

--
>
Regards,
Peng

--
You received this message because you are
> subscribed to the ggplot2 mailing list.
Please provide a reproducible
> example: http://gist.github.com/270442

To post: email > ymailto="mailto:ggp...@googlegroups.com"
> href="mailto:ggp...@googlegroups.com">ggp...@googlegroups.com
To
> unsubscribe: email ggplot2+> href="mailto:unsub...@googlegroups.com">unsub...@googlegroups.com
More
> options: http://groups.google.com/group/ggplot2


Felipe Carrillo

unread,
May 31, 2010, 3:59:56 PM5/31/10
to r-h...@stat.math.ethz.ch, ggplot2
With ggsave the graph windows pops up but using:

png("mypng.png")
qplot(X, data=data, geom='histogram') + facet_wrap( ~ Y)
dev.off()
The graph is saved in the background
Is there a way to hide the graph window when
using ggsave?

Hadley Wickham

unread,
May 31, 2010, 4:06:22 PM5/31/10
to Peng Yu, ggplot2
> p=qplot(X, data=data, geom='histogram') + facet_wrap( ~ Y)
> save(p, file='error.png')
>
> The above qplot work properly if I don't plot it to a file. But if I
> plot it to a png file, the png file is always corrupted. Would you
> please let me know what is wrong?

Save is for storing a binary representation of R objects on disk, not
for saving images.

Hadley

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Bunny, lautloscrew.com

unread,
May 31, 2010, 4:23:35 PM5/31/10
to Hadley Wickham, Peng Yu, ggplot2
Peng Yu, 

filename="my.pdf"
ggsave(filename,scale=1.5)

worked perfectly fine for me with virtually any plot created with qplot.

HTH

matt


--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442

Reply all
Reply to author
Forward
0 new messages