【问题标题】:How do I add reference lines in trellis dot plots in R in the lattice package如何在格子包中的 R 中的格状点图中添加参考线
【发布时间】:2016-02-08 03:41:25
【问题描述】:

以下代码完全按照我的意愿生成网格点图,但我想自动将参考线添加到四个面板。我已经尝试搜索可以让我这样做的代码示例,但到目前为止还没有运气。谁能建议一个简单的解决方法?

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"))))

谢谢,

迈克

【问题讨论】:

  • 函数layerpanel.abline 来自latticeExtra

标签: r lattice trellis


【解决方案1】:

取决于您希望参考线的位置。如果您需要自己放置它们,请使用panel.refline()。 (它本质上是panel.abline() 的包装,用更适合参考线的样式替换该函数的默认样式。)

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

或者,如果您只是想要一个参考线网格 à la ggplottype= 参数提供了一种简单的获取方法:

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

【讨论】:

  • 这太容易了。非常感谢。此外,作为发现 'type' 参数的结果,我还发现 'grid = TRUE' 做同样的事情。
  • @MikeO'Connor 啊,很好的发现,感谢提及。干杯。
猜你喜欢
  • 2014-06-28
  • 2015-09-16
  • 2019-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-22
相关资源
最近更新 更多