Draw grid lines on specific values in xyplot

前端 未结 3 2238
傲寒
傲寒 2021-02-10 04:34

I have a xyplot and I want to draw grid lines on the 0 values.

How this can be done?

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-10 05:11

    If you're using package lattice (which is implied with xyplot), you can use panel.abline to draw lines over labeled ticks.

    my.df <- data.frame(a = runif(10, min = -1, max = 1), b = runif(10, min = -1, max = 1))
    my.plot <- xyplot(b ~ a, data = my.df)
    update(my.plot, panel = function(...) {
                panel.abline(h = 0, v = 0, lty = "dotted", col = "light grey")
                panel.xyplot(...)
            })
    

    enter image description here

提交回复
热议问题