Take a very simple example, mfrow=c(1,3); each figure is a different histogram; how would I draw a horizontal line (akin to abline(h=10)) that went across all 3 figures? (That is, even the margins between them.) Obviously, I could add an abline to each figure, but that’s not what I want. I can think of a very complicated way to do this by really only having 1 figure, and drawing each ‘figure’ within it using polygon etc. That would be ridiculous. Isn’t there an easy way to do this?
Take a very simple example, mfrow=c(1,3) ; each figure is a different histogram; how
Share
As @joran noted, the grid graphical system offers more flexible control over arrangement of multiple plots on a single device.
Here, I first use
grconvertY()to query the location of a height of 50 on the y-axis in units of “normalized device coordinates”. (i.e. as a proportion of the total height of the plotting device, with 0=bottom, and 1=top). I then use grid functions to: (1) push aviewportthat fills the device; and (2) plot a line at the height returned bygrconvertY().EDIT: @joran asked how to plot a line that extends from the y-axis of the 1st plot to the edge of the last bar in the 3rd plot. Here are a couple of alternatives:
Finally, here’s an almost equivalent, and more generally useful approach. It employs the functions
grid.move.to()andgrid.line.to()demo’d by Paul Murrell in the article linked to in @mdsumner’s answer: