2

The following piece of code produces a trellis dot plot exactly as I would like it, but I would like to automatically add reference lines to the four panels. I have tried searching for examples of code that will let me do this, but so far no luck. Can anyone suggest a simple fix?

dotplot(region ~ productivity | los,
panel = panel.superpose,
group = month,
between = list(x=1, y=0),
index.cond = list(c(4,2,1,3)),
pch = 1:4, col = 1:4,
main = "Monthly Productivity by LoS by Region",
xlab = "Percent",
aspect = 1, 
key = list(space = "right",
    transparent = TRUE,
    points = list(pch = 1:4,
    col = 1:4),
    text = list(c("Jul", "Aug", "Sep", "Oct"))))

Thanks,

Mike

1 Answers1

3

Depends on where you'd like to have the reference lines. If you need to place them yourself, then use panel.refline(). (It's essentially a wrapper for panel.abline(), replacing that function's default stylings with ones more appropriate for reference lines.)

xyplot(mpg ~ disp, data = mtcars,
       panel = function(x,y,...){
           panel.refline(h = c(15,17))
           panel.xyplot(x,y,...)
       })

enter image description here

Alternatively, if you're just wanting a grid of reference lines à la ggplot, the type= argument offers a simple way to get one:

xyplot(mpg ~ disp, data = mtcars, type = c("g", "p")) ## "g"rid and "p"oints 

enter image description here

Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455