How to add abline with lattice xyplot function?

2020-02-10 06:15发布

I am trying to plot two variables: Eeff vs Neff using xyplot function of lattice package. I would like to know how to add an line to this scatter plot (which is abline function in normal R graphic system).

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

标签: r lattice
1条回答
够拽才男人
2楼-- · 2020-02-10 07:05

The lattice package has several "panel functions", one of which is panel.abline.

Try this and see if it gives you what you're looking for:

xyplot(Neff ~ Eeff, data = phuong,
       panel = function(x, y) {
         panel.xyplot(x, y)
         panel.abline(lm(y ~ x))
       }, 
       xlab = "Energy efficiency (%)", 
       ylab = "Nitrogen efficiency (%)")
查看更多
登录 后发表回答