[R] How to extract one of four plots in a linear regression model
alain.guillet at uclouvain.be
Thu Feb 25 17:15:30 CET 2010
You can extract a plot in using the option which in specifying the
number of the plot (from 1 to 6). For example:
> plot(lm.D9, which=1)
On 25-Feb-10 16:50, FMH wrote:
> Dear All,
> A linear regression model could be fitted by using lm function and the plot function can be used to check the assumption of the model.
> The help menu shows few instances on suitable coding for fitting such a linear model. In addition, four different plots could be extracted simultaneously with only a single plot function as followed:
> ## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
> ## Page 9: Plant Weight Data.
> ctl<- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
> trt<- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
> group<- gl(2,10,20, labels=c("Ctl","Trt"))
> weight<- c(ctl, trt)
> anova(lm.D9<- lm(weight ~ group))
> opar<- par(mfrow = c(2,2), oma = c(0, 0, 1.1, 0))
> plot(lm.D9, las = 1)
> The plot function gives four different plots simulaneously but i just need only part of them, for instance the normality plot. Could someone give some ideas the way to extract this single plot as i need to copy only this plot and paste it into Word document.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Statistician and Computer Scientist
SMCS - Institut de statistique - Université catholique de Louvain
Voie du Roman Pays, 20
tel: +32 10 47 30 50
More information about the R-help