【问题标题】:How to add abline with lattice xyplot function?如何使用 lattice xyplot 函数添加 abline?
【发布时间】:2012-08-14 09:50:11
【问题描述】:

我正在尝试绘制两个变量:Eeff vs Neff 使用 lattice 包的 xyplot 函数。我想知道如何在这个散点图中添加一条线(这是普通 R 图形系统中的 abline 函数)。

xyplot(Neff ~ Eeff, data = phuong,
       xlab = "Energy efficiency (%)", 
       ylab = "Nitrogen efficiency (%)")

【问题讨论】:

    标签: r lattice


    【解决方案1】:

    lattice 包有几个“面板功能”,其中之一是panel.abline

    试试这个,看看它是否能满足您的需求:

    xyplot(Neff ~ Eeff, data = phuong,
           panel = function(x, y) {
             panel.xyplot(x, y)
             panel.abline(lm(y ~ x))
           }, 
           xlab = "Energy efficiency (%)", 
           ylab = "Nitrogen efficiency (%)")
    

    【讨论】:

    • 代码在大括号后面需要一个逗号:所以是panel = function(x, y) { ... } , xlab = ...
    猜你喜欢
    • 1970-01-01
    • 2016-01-29
    • 1970-01-01
    • 1970-01-01
    • 2011-12-03
    • 2013-07-30
    • 1970-01-01
    • 2011-11-29
    • 1970-01-01
    相关资源
    最近更新 更多