Posts Tagged ‘R’

The GNU R software environment for statistical computing and graphics.

Duplicating ggplot axis labels

Wednesday, July 21st, 2010

I’ve been trying for a while to find an elegant solution for duplicating axis ticks and labels in a ggplot chart. Hadley replied on the ggplot2 mailing list, but a working solution within ggplot2 seems a way off.

The situation is this: imagine you have a faceted plot that is tall enough that the x-axis ticks and labels become obscured (e.g. when using a clipped viewport such as a browser window). This is particularly destructive when you’re using an x-scale with manual breaks or a transformation.

g <- ggplot(diamonds, aes(carat, ..density..)) + 
   geom_histogram(aes(fill = clarity), binwidth = 0.2) + 
   facet_grid(cut ~ .)

Faceted Plot where the x-axis labels have been clipped out

There simply isn’t a way to repeat the x-axis labels in ggplot2 at the moment without discarding faceting and rendering each facet as a separate ggplot call. I’ve seen some examples of selective plotting used to good effect in combining multiple plots with common elements, but I can’t find anything applicable to keep consistent scales and binning without duplicating a lot of the (internal) facet and bin logic.


R and LaTeX PDF graphics

Monday, May 17th, 2010

When writing a document in LaTeX that makes use of figures from R, I want to produce a PDF with

  • vector graphics,
  • consistent fonts,
  • not to mess around overlaying text in LaTeX,

and maybe typeset math in the R graphics. This post surveys the state of the art in how to achieve the best of all worlds when importing graphics generated by R into documents typeset to PDF with LaTeX. I look at postscript and PDF figures generated by R’s X11, Cairo, and finally the new (and awesome) TikZ devices.