Gareth.Williams at csiro.au
2012-Jun-13 06:30 UTC
[R] add horizontal reference lines in lattice bwplot
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
Hello Gareth, Concerning the lines, you can try : panel.abline(h=13) and panel.grid(h=2, v=0, y=c(11, 12), col.line="blue") I have no idea for the annotation. Sorry. Ptit Bleu. -- View this message in context: http://r.789695.n4.nabble.com/add-horizontal-reference-lines-in-lattice-bwplot-tp4633214p4633219.html Sent from the R help mailing list archive at Nabble.com.
Gareth.Williams at csiro.au
2012-Jun-13 11:29 UTC
[R] add horizontal reference lines in lattice bwplot
> -----Original Message----- > From: PtitBleu [mailto:ptit_bleu at yahoo.fr] > Sent: Wednesday, 13 June 2012 5:46 PM > To: r-help at r-project.org > Subject: Re: [R] add horizontal reference lines in lattice bwplot > > Hello Gareth, > > Concerning the lines, you can try : > panel.abline(h=13) > and > panel.grid(h=2, v=0, y=c(11, 12), col.line="blue") > > I have no idea for the annotation. Sorry. > > Ptit Bleu.Thanks! I did not understand that I needed to use the log10 of the value for the grid position to match the log scale. The panel.abline now works. I could not get the panel.grid to work but just using abline is fine. I also figured out how to use panel.text with my new knowledge of the grid coordinate system. Gareth> > > -- > View this message in context: http://r.789695.n4.nabble.com/add- > horizontal-reference-lines-in-lattice-bwplot-tp4633214p4633219.html > Sent from the R help mailing list archive at Nabble.com. >