【问题标题】:r lattice - wrong position of horizontal abline after bwplotr lattice - bwplot 后水平 abline 的错误位置
【发布时间】:2013-08-16 13:47:59
【问题描述】:

我可以毫无问题地做到这一点:

boxplot(coef ~ habitat, data = res)
abline(h = 0, col = "green")

但是当我使用lattice时,水平线错位了:

bwplot(coef ~ habitat, data = res)
abline(h = 0, col = "green")

我尝试改用panel.abline,但这会将绿线放在图片顶部。

【问题讨论】:

    标签: r plot lattice boxplot


    【解决方案1】:

    使用面板功能;按照您希望添加部件的顺序对包含的功能进行排序;利用... 避免必须知道/管理面板功能的所有参数

    bwplot(coef ~ habitat, data = res, panel=function(...) {
        panel.abline(h=0, col="green")
        panel.bwplot(...)
    })
    

    当有多个面板时,面板函数的概念更有意义,例如,

    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, ...)
    })
    

    【讨论】:

    • 谢谢马丁,很有魅力!这是非常奇怪的语法,我不确定我是否会进入 lattice :-)
    猜你喜欢
    • 1970-01-01
    • 2021-01-31
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 2011-12-03
    • 1970-01-01
    • 1970-01-01
    • 2021-10-25
    相关资源
    最近更新 更多