Search code examples
rplotfigure

Use par inside another par


I do not sure if this even possible but I am attaching a figure I like to do it in R instead of using paint. Example figure

x=rnorm(10,4,5)
y=rnorm(10,4,5)

par(mfrow=c(2,1))
plot(x,y)

par(mfrow=c(1,3))
plot(x,y)
plot(x,y)
plot(x,y)

Solution

  • enter image description here

    I assume you are looking for a base-like way of doing this, but you can also used ggplot. Here are both solutions.

    library(grid)
    library(gridExtra)
    library(ggplot2)
    x=rnorm(10,4,5)
    y=rnorm(10,4,5)
    
    m <- matrix(c(1,1,1,2,3,4),nrow=2,byrow=TRUE)
    layout(m)
    
    plot(x,y)
    plot(x,y)
    plot(x,y)
    plot(x,y)
    
    p1 = ggplot(data.frame(x=x, y=y), aes(x, y))+geom_point()
    grid.arrange(p1, p1, p1, p1, layout_matrix = m)