1

The problem is that I managed to graph this:

enter image description here

by writing this:

par(mar=c(0,4,2,1)+.1)

shap <- shapiro.test(as.numeric(residuals.arima))$p.value
qqnorm(residuals.arima, main=c("Normal Q-Q Plot", paste("Shapiro p=", prettyNum(shap, digits = 2))))
qqline(residuals.arima)

op <- par(fig=c(.02,.5,.5,.98), new=TRUE)
hist(residuals.arima, breaks=22, probability=T,
 col="grey", xlab="", ylab="", main="", axes=F)
lines(a,dnorm(a,mean(residuals.arima), sd(residuals.arima)), lty=1, col="darkblue", lwd=2)
box()
par(op)

Now, this is exactly the way I'd like the two plots to be visualized together. I do not want to split them up.

However I'd like to put everything in the right panel (2) of a structure like the following, so that I can add another plot on panel (1) without everything messing up:

layout(matrix(c(1,2), nr=1, byrow = TRUE))

enter image description here

How can I do this?

toyo10
  • 121
  • 1
  • 14
  • Possible duplicate of [How to separate two plots in R?](https://stackoverflow.com/questions/1801064/how-to-separate-two-plots-in-r) – Roman Mar 12 '18 at 16:16
  • after your `par(op)` you can reset the `layout`, set the second panel to be the next one drawn upon, then do your plot: `...; par(op); layout(t(1:2)); par(mfg = 1:2); plot(rnorm(10))` – rawr Mar 12 '18 at 16:36
  • It's not a duplicate. I don't want to split the graph on the two panels. – toyo10 Mar 12 '18 at 16:58

1 Answers1

1

If I understand you correctly you want to simply do this:

par(mfrow=c(1,2))
qqplot(...)
qqline(...)

hist(...)
lines(...)

Alternative interpretation of what you are after is to put everything you have on that second side and leave the first side blank (to be used for something else). If that is the case you can use screen:

figs <- rbind(c(0, 0.5, 0, 1),    # Screen1
              c(0.5, 1, 0, 1),    # Screen2
              )
colnames(figs) <- c("W", "E", "S", "N")
rownames(figs) <- c("Screen1", "Screen2")

screenIDs <- split.screen(figs)
names(screenIDs) <- rownames(figs)

screen(screenIDs["Screen1"])

# Everything that should go on the left side goes here

screen(screenIDs["Screen2"])

# The current plots you have go here
Karolis Koncevičius
  • 9,417
  • 9
  • 56
  • 89