Ram Pandit <pandit.ram <at> gmail.com> writes: > I am working in a country level data. After running the regression, I would > like to plot the residuals of each observation based on the group created > for a particular variable. > > For example, one of my independent variable is "Income", I would like to > plot the residual based on income categories (<5000, 5001-10,000, > 10001-15,000 etc) with "different color" for each income group. > > Any hints or pointers will be highly appreciated.
(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) }) ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.