简体   繁体   中英

Create subplots in a subplot in R

I'm trying to arrange my plots as shown in the figure in R.

I can create a 2 by 2 plot matrix using:

par(mfrow=c(2,2))

Is it possible to further create subplots within the 4th square as shown in the figure? 在此处输入图像描述

Thanks!

You can use the layout function to arrange graphics plots. layout takes a matrix that indicates the order in which to add plots to the graphics device.

m1 <- matrix(c(
    1, 1, 2, 2, 
    1, 1, 2, 2, 
    3, 3, 4, 5, 
    3, 3, 6, 7), nrow = 4, ncol = 4, byrow = TRUE)
m1
#      [,1] [,2] [,3] [,4]
# [1,]    1    1    2    2
# [2,]    1    1    2    2
# [3,]    3    3    4    5
# [4,]    3    3    6    7
layout(m1)
hist(rnorm(100), col = "red")
hist(rnorm(100), col = "orange")
hist(rnorm(100), col = "yellow")
hist(rnorm(100), col = "green")
hist(rnorm(100), col = "lightblue")
hist(rnorm(100), col = "blue")
hist(rnorm(100), col = "violet")

显示图形添加位置的彩色直方图

You will need to make sure the graphics device is large enough to receive large numbers of plots.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM