r格子-bwplot后水平abline的错误位置 [英] r lattice - wrong position of horizontal abline after bwplot
本文介绍了r格子-bwplot后水平abline的错误位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以做到这一点而没有问题:
I can do this without problems:
boxplot(coef ~ habitat, data = res)
abline(h = 0, col = "green")
但是当我使用点阵时,水平线放错了位置:
But when I use lattice, the horizontal line is misplaced:
bwplot(coef ~ habitat, data = res)
abline(h = 0, col = "green")
我尝试改用panel.abline
,但是这会将绿线放在图片的顶部.
I tried to use panel.abline
instead but that places the green line on top of the picture.
推荐答案
使用面板功能;按照您希望添加零件的顺序订购所包含的功能;利用...
避免必须了解/管理面板功能的所有参数
Use a panel function; order the contained functions in the order you'd like parts added; make use of ...
to avoid having to know / manage all parameters to the panel function
bwplot(coef ~ habitat, data = res, panel=function(...) {
panel.abline(h=0, col="green")
panel.bwplot(...)
})
当有多个面板时,面板功能的概念更有意义,例如,
The notion of a panel function makes more sense when there are several panels, e.g.,
res = data.frame(coef=rnorm(99) + (-1):1, habitat=sample(letters[1:3], 99, TRUE),
grp=c("W", "X", "Y"))
bwplot(coef ~ habitat | grp, data = res, panel=function(x, y, ...) {
## green line at panel-median y value
panel.abline(h=median(y), col="green")
panel.bwplot(x, y, ...)
})
这篇关于r格子-bwplot后水平abline的错误位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文