[R] add horizontal reference lines in lattice bwplot
Gareth.Williams at csiro.au
Gareth.Williams at csiro.au
Wed Jun 13 08:30:30 CEST 2012
I'm plotting a lattice bwplot from a data.frame and would like to add some horizontal lines indicating some reference values (preferably with text annotation) as well as a grid of regular log tics. The following illustrates the plot:
data(ToothGrowth)
require("lattice")
p = bwplot(exp(len) ~ supp, ToothGrowth,
panel = function(..., box.ratio) {
panel.grid(h=-1, col.line="grey")
panel.violin(..., col = "lightblue", adjust = 1.0,
varwidth = FALSE, box.ratio = box.ratio, log = 'y')
panel.bwplot(..., fill = NULL, box.ratio = .1, log = 'y')
}, scales=list(y=list(log=TRUE)))
(The actual data I am working with represents bandwidth achieved in a set of tests at times and a log scale seems appropriate. Also there are many tests).
I've tried the following to add horizontal lines with no success. I get no abline at all and just two evenly spaced grid lines.
panel.abline(h=10^13, col.line="red")
panel.grid(h=2, v=0, y=c(10^11, 10^12), col.line="blue")
Also I have no idea where to start annotating the lines (well panel.text seems the place to start).
FWIW I tried ggplot2 also, but the violins it produces for my data get lost in the scale I need as the distributions for some tests are much narrower than for others (and far from normal).
Gareth Williams
CSIRO
More information about the R-help
mailing list