Tutorial :How to separate linear regression plots in R?


For a linear model with 2 variables

r = lm(y ~ x1+x2)  

When I run plot(r) , I get a bunch of plots such as residuals vs fitted values and so on , but I can only look at one of them at a time .

Isn't there a way to separate them ?


A few ways. The most convenient is layout. ?layout for more details

r<-lm(y~x1+x2)  layout(matrix(1:4,2,2))  plot(r)  

will produce a window with four plots.


You could use the line:




In that way you say to R to show 4 pictures at the same frame. You can also set 4,1 to have 4 graphs one above the other, or 1,4 to have 4 graphs one on the side of the other.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »