[R] add reference lines (or grid) in background

Jim Lemon jim at bitwrit.com.au
Tue Sep 18 12:25:43 CEST 2012


On 09/18/2012 06:35 PM, Luigi wrote:
> Dear all,
>
> Is there a simple way to add reference lines in background? I am trying with
> abline() or grid() but the lines, since they are executed after the plot
> function, are draw on top. How can I draw such lines beneath the main plot?
> Here is an example:
>
>
>
> x<-rnorm(100)
>
> boxplot(x)
>
> abline(h=c(-1,0,1))
>
> grid(NA, 4, lwd = 2)
>
>
>
Hi Luigi,
There are a few different ways to get your grid "under" the plot. 
Perhaps the most straightforward is to display the plot, then the grid, 
then "add" the plot on top using the "add" argument.

The box.heresy plot in the plotrix package is one of the functions that 
has a "do.first" argument. This can be a call to "grid" and displays the 
grid before the plot. This involves only one call, but it is a bit 
different from the standard boxplot.

Jim




More information about the R-help mailing list