将abline添加到xyplot(半日志)

时间:2015-12-09 23:56:57

标签: r lattice

我正在尝试在logscale上添加带有y轴的xyplot上的abline。我可以添加 当y不在对数刻度时使用abline但是当y在对数刻度时它不起作用。

请提出任何建议!

谢谢!

library(lattice)
y <- c(2,10,25,70)
x <- c(0.2,0.3,0.5,1)

xyplot(y~x,
  type='b',
  scales=list(y=list(log=TRUE)),
  panel = function(x, y) {
    panel.xyplot(x, y)
    panel.abline(h=8.8)
  }
)

1 个答案:

答案 0 :(得分:2)

Oddly lattice does not handle the log scale correctly for abline. But it seems to work if you do the calculation for lattice:

library(lattice)
y <- c(2,10,25,70)
x <- c(0.2,0.3,0.5,1)

xyplot(y~x,
       type='b',
       scales=list(y=list(log=T)),
       panel = function(x, y) {
         panel.xyplot(x, y)
         panel.abline(h=log(8.8,10))
       }
)

enter image description here