[R] adding text to y-axis per row of panels (lattice)

E Hofstadler e.hofstadler at gmail.com
Thu Jan 20 09:34:02 CET 2011

Dear all,

Being a newbie to R, I've trawled through many old posts on this list
looking for a solution to my problem, but unfortunately couldn't quite
figure it out myself. I'd be very grateful if someone here on this
list could perhaps help me out.

I have a lattice plot with several panels and would like to add some
text next to the y-axis on the right hand side of each row of panels.
This text should help the reader to interpret the value ranges of the
y-axis: so the range between -1 and 1 (in between the two reference
lines) should e.g. labelled "balanced", the rest of the positive scale
as "too high", and the rest of the negative scale as "too low". The
text should be printed in parallel to the y-axis.

If this was a base graphic plot, I'd use mtext, but I'm not sure how
to get to the same results when using lattice.

Here is some example data:

varx <- c(1:4,1:4,1:4,1:4)
vary <- c(2,2,1.5,0.3,1,2,3,4,-1,-0.5,3,-1,-1,-0.5,1,-3)
condvar <- c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4)
exampledata <-data.frame(cbind(varx,vary,condvar))
xyplot(vary~varx|condvar, type="o",data=exampledata,
panel=function(x,y,...){  panel.abline(h=-1)

Any help is greatly appreciated!


More information about the R-help mailing list