« R Graph Gallery | Main | Statistics and the Superbowl »

January 30, 2009


Feed You can follow this conversation by subscribing to the comment feed for this post.

Nice post! I would, however, recommend using a PNG optimizer, such as OptiPNG to reduce the filesize of PNG files. Here is an example:

$ optipng mygraphic.png

OptiPNG 0.5.5: Advanced PNG optimizer.

Copyright (C) 2001-2007 Cosmin Truta.

** Processing: mygraphic.png

400x350 8-bit palette non-interlaced

The image is losslessly reduced to 1-bit palette

Input file size = 1651 bytes

Output file size = 689 bytes (962 bytes = 58.27% decrease)

If you make a pdf (tip #3), how do you place that graphic in another document (e.g. in MS word)? I usually make PNGs and then "insert a picture". But, as you say, the printed version never looks as nice.

Never mind my previous comment. I'm an idiot; don't know how I managed to skip tip #4 which addresses the very issue. :-/

Wcyee, you also might like to take a look at the win.metafile() graphics device. Like the postscript() device, it generates vector graphics, so you don't have to worry about pixel resolutions and it should result in good printed output. I have heard that Windows applications like Word will display a Windows MetaFile graphics on-screen, but I don't have Windows and so can't check. But it might be worth a try.

Cool, thanks for the tip, David. I'll definitely give it a shot since this is something that has bugged me for a while now.

wow from the comments alone i got so many interesting Tutorials..thank you for writing this article...

This algorithm is definitely going to reduce the amount and effort for displaying a beautiful statistical graphic in R without much coding work.

Excellent Post--very helpful indeed.

nice post. Me, I'm exporting graphs to WMF , so I can be put them in Openoffice.ODT or MS.DOC.

Unfortunately this only works under Windows and the wmfs disappear from the ODT document under Linux.

I will probably use your advice and move to PNG for that purpose.

Nice post. One small quibble, you can use dev.copy much the same way as png by supplying additional arguments, which is helpful if you wanna see on the fly what you are saving. png and other have the advantage that the may not need an actual grpahical display so you can run them on a server etc.

In your brain/body plots it'd be nice to use figures instead of text (eg. a picture of a mouse rather than the word "Mouse"). I haven't found a nice way to do this yet - bonus marks if you find something that can embed vector graphics in a plot.

The polypath function can draw vector graphics -- Simon Unbanek showed a great example of reproducing a PDF map with it at useR! 2011. But for a mouse you're more likely to use a photo, in which case the rasterimage function will do what you need.

Mmmm. It looks close. The Spanish flag example given here unfortunately converts a lovely SVG into a PNG file. Otherwise rasterimage looks great.

You saved my life! ;-)

- Quit the borders of every box you will draw ever. (border=NA, axes=FALSE, bty="n")
- Use the rainbow() function. If there is too much color you can use the Agave app for choose your colors.
- Know the outputs of the plot functions, maybe you can make some with this.

png(file="notitle.png",width=400, height=350)
PLOT<-barplot(c(1,3,2,4), ylab=NULL, main=NULL, col=rainbow(4), border=NA, ylim=c(0,5), axes=FALSE)
text(x = PLOT, y=c(1,3,2,4), labels=c(1,3,2,4), pos=3)
legend("topleft", legend=c(1,2,3,4), fill=rainbow(4), bty="n", border=NA)

The comments to this entry are closed.

Search Revolutions Blog

Got comments or suggestions for the blog editor?
Email David Smith.
Follow revodavid on Twitter Follow David on Twitter: @revodavid
Get this blog via email with Blogtrottr