Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add abline with lattice xyplot function?

Tags:

r

lattice

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 (%)")
like image 883
hn.phuong Avatar asked Aug 14 '12 09:08

hn.phuong


1 Answers

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 (%)")
like image 52
A5C1D2H2I1M1N2O1R2T1 Avatar answered Nov 08 '22 11:11

A5C1D2H2I1M1N2O1R2T1