A lot of attention recently has gone to the more modern (and, dare I say, sexier) graphics systems in R, ggplot2 and lattice. But there's a lot of power in the base graphics system built into core R, especially when you want control over every aspect of how the graph is laid out. Ryan Rosario has put together some slides detailing some more advanced tricks capable with the base graphics system. For example:
- How to create custom axes (for example, an axis on the right, or an axis labelled by dollars or other custom quantity)
- How to overlay multiple scatterplots (and set the scaling of the axes appropriately)
- How to create a custom legend
- How to add gridlines to your graph
- How to specify colors
- And even how to create a movie from your graph
All the details are in Ryan's slides, and yes, the R code to create the example charts is also available.
Byte Mining: Advanced Graphics in R



I like a lot of the points made here, but:
* why not mention par(las=1) for horizontal axis labels (which should be the default for readability, except that it usually requires adjustment of margin size (mar) and y-label placement (mgp or axis(...,lines=))? par(bty="l") is nice too, and adjusting the number of ticks on the axes ...
* the "R learning curve" plot is very un-Tufte-ish -- as long as we're going in that direction, why not at least use a gray grid? And why not use the built-in grid() function? And perhaps work it out so the grid is *underneath* the line? (In general this presentation shades toward "because you can" rather than "because it makes the graphic represent the data more clearly" ...)
* why not use polygon() to shade the area under the curve in the integral example?
Posted by: Ben Bolker | February 05, 2010 at 12:50
I would like to know how to plot a confidence interval using smoothScatter function as in this figure4 (http://www.plosgenetics.org/article/info:doi%2F10.1371%2Fjournal.pgen.1000562).
Posted by: Wagner Magalhaes | February 16, 2010 at 13:22