0

Good Morning,

Am new to R. I am trying to combine 9 plots, arranging it to 3 x 3.

I have a) 7 leveragePlots() syntax that creates 1 plot each,and b) the 8th leveragePlots() generates 2 plots as it is two variable linear model fit.

When using the below, the first 7 plots where arranged well, but the last one does not fit into the 3x3 grid but opens a new window with 2 plots.

Minimal Dataset (sample.txt):

X   Y
276.67  5.20
285.00  5.17
296.67  4.96
307.50  5.26
307.50  5.11
262.50  5.27
278.33  5.20
282.50  5.16
267.50  5.17
250.00  5.20
275.00  5.18
274.17  5.09
311.67  5.03
294.17  5.21
279.17  5.29
300.00  5.14
292.50  5.09
297.50  5.16
290.00  4.99
272.50  5.23
289.17  5.32
279.17  5.21
325.83  5.14
292.50  5.22
255.83  5.15
290.83  5.09
283.33  5.09
284.17  5.07
298.33  5.27
269.17  5.19

Tried using par(mfrow=c(3,3)) and also layout(matrix(c(1,2,3,4,5,6,7,8,8), 3, 3, byrow = TRUE)). It is not working. Still opening new window for the last syntax of leveragePlots(). To replicate the codes are below,

library(car)
sampledata <- read.table("D:/sample.txt", header=TRUE)
y.1 <- sampledata$Y
x.1 <- sampledata$X
x.2 <- (sampledata$X)^2

par(mfrow=c(3,3))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1 + x.2))

Do you know how I can force the final 2 plots to be placed in the same 3x3 layout? If you do, please advice me.

Am currently reading on layout() at http://rfunction.com/archives/1538 ,not sure how to use this to achieve the above.

Thanks for your lead.

Saravanan K
  • 672
  • 3
  • 10
  • 27
  • 1
    We cannot reproduce your plot as you haven't provided the objects, in this case `y.1` to `y.8`. Please read [this post](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and add the objects or make up some data so that we can just copy and paste your code. I have added the library call for you. – SlowLearner Dec 23 '13 at 11:44
  • @SlowLearner Sorry if I was not being complete. Have duly included the sample data and codes to replicate this problem. Thanks for your headsup. – Saravanan K Dec 23 '13 at 12:08

1 Answers1

3

Revised solution, now using provided data.

par(mfrow=c(3,3))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1))
leveragePlots(lm(y.1 ~ x.1 + x.2), layout = NA)

enter image description here

datawookie
  • 1,607
  • 12
  • 20
  • Thanks for the suggestion. Tried this approach and still it is not working. I have updated my writeup above and included a sample data and codes to replicate the problem. Believe you will see the same problem I am facing at my side. Thanks once again – Saravanan K Dec 23 '13 at 12:09