Skip to content
Prev 305748 / 398506 Next

add reference lines (or grid) in background

There is a "panel.first" argument that can be used with many different
types of plots.

plot(x, panel.first=abline(h=-3:3, lty="dotted", col="gray"), pch=16,
col="red", cex=3)
# red big plotting characters: to show that ablines are drawn before plotting
# the result is different from doing the plot first and abline's after that.

But this doesn't work with boxplot: ablines are drawn (so panel.first
does something) but then overplotted.

boxplot(x, panel.first=abline(h=-3:3,  lwd=100, col="red"))
# lwd=100: this would be absurd if it worked but now I can see only
something red flashing
# on the screen before the boxplot is drawn

Maybe there are some extra parameters to boxplot or bxp (which does
the drawing) that could be used (from what I see on the screen I can
imagine that the ablines are first drawn but deleted by the white
background of boxplot; so it might help to make this background
transparent instead of white; but I haven't examined the code so can't
be sure this is what bxp does). Or it might be easier to do it with
ggplot.

Regards,

Kenn Konstabel
On 9/18/12, John Kane <jrkrideau at inbox.com> wrote: