Skip to content

How to create grouping in the residual plot

2 messages · Ram Pandit, Dieter Menne

#
Ram Pandit <pandit.ram <at> gmail.com> writes:
(Any sample data set would also be appreciated)


library(nlme) # only required for data set
library(lattice)
data(Orthodont)
lm.or = lm(distance~age+Sex,data=Orthodont)
Orthodont$res = residuals(lm.or)
# in one plot
xyplot(res~age,groups=Sex,data=Orthodont)
# in two panels, with a bit of additional luxury
xyplot(res~age|Sex,data=Orthodont,aspect=1,
      panel = function(x, y) {
           panel.grid(h=-1, v= -2)
           panel.xyplot(x, y,pch=16)
           panel.loess(x,y, span=1)
       })