I have already created 4 plots
x1 <- rnorm(10)
x2 <- rnorm(10)
x3 <- rnorm(10)
x4 <- rnorm(10)
par(mfrow=c(2,2))
plot(x1,t="p",main = "1")
plot(x2,t="p",main = "2")
plot(x3,t="p",main = "3")
plot(x4,t="p",main = "4")
I want to add a line to the first plot.. I can add a line at the initial stage of running the code
x1 <- rnorm(10)
x2 <- rnorm(10)
x3 <- rnorm(10)
x4 <- rnorm(10)
par(mfrow=c(2,2))
plot(x1,t="p",main = "1") ; lines(rnorm(10),col=2)
plot(x2,t="p",main = "2")
plot(x3,t="p",main = "3")
plot(x4,t="p",main = "4")
But the question is : how to add a line to the first plot after all four plots already exist, like in first picture
x1 <- rnorm(10)
x2 <- rnorm(10)
x3 <- rnorm(10)
x4 <- rnorm(10)
par(mfrow=c(2,2))
plot(x1,t="p",main = "1")
plot(x2,t="p",main = "2")
plot(x3,t="p",main = "3")
plot(x4,t="p",main = "4")
# how to add line in first plot now ?
lines(rnorm(10),col=2)
CodePudding user response:
The graphical parameter mfg
:
A numerical vector of the form
c(i, j)
wherei
andj
indicate which figure in an array of figures is to be drawn next (if setting) or is being drawn (if enquiring). The array must already have been set bymfcol
ormfrow
.
par(mfrow = c(2, 2))
plot(x1, main = "1")
plot(x2, main = "2")
plot(x3, main = "3")
plot(x4, main = "4")
par(mfg = c(1, 1))
lines(rnorm(10), col = 2)