如何在R中的布局内调整单个图的边距?

Dan*_* C. 5 layout plot r margins par

我有一个由7个图组成的布局,一个在顶部,另一个6在第一个图的3x2矩阵下方展开。在我的布局中,这些图完全在一起,我想在第一个图和其他图之间留一点点高。我如何在R中做到这一点?

layout(matrix(c(1,1,2,3,4,5,6,7), 4, 2, byrow = T))

par(mar = c(0,0,0,0), oma = c(5,4,0.5,0.5), las =1)


plot(1:10, axes = T, type = "n", xlim = c(0,30), ylim = c(-3,2), las =1)
mtext(letters[1], side = 3, line = -1.5, adj = 0.025)

for (i in 2:7){
  plot(1:10, axes = F, type = "n", xlim = c(0,30), ylim = c(-3,1.8))
  mtext(letters[i], side = 3, line = -1.5, adj = 0.025)

  if (i %in% c(6,7))
    axis(side = 1)

  if (i %in% c(2,4,6))
    axis(side = 2)
  box()
}
mtext("x axis", side = 1, outer = TRUE, line = 3)
mtext("y axis", side = 2, outer = TRUE, line = 3, las = 3)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

我想要类似的东西

在此处输入图片说明

Dan*_* C. 6

在第一个图之前,在底轴上添加边距

par(mar = c(2.5,0,0,0))
Run Code Online (Sandbox Code Playgroud)

然后,开始for删除此边距

par(mar = c(0,0,0,0))
Run Code Online (Sandbox Code Playgroud)

完整代码:

layout(matrix(c(1,1,2,3,4,5,6,7), 4, 2, byrow = T))

par(mar = c(0,0,0,0), oma = c(5,4,0.5,0.5), las =1)

par(mar = c(2.5,0,0,0)) #Add a space in the bottom axis

plot(1:10, axes = T, type = "n", xlim = c(0,30), ylim = c(-3,2), las =1)
mtext(letters[1], side = 3, line = -1.5, adj = 0.025)

for (i in 2:7){

  par(mar = c(0,0,0,0)) #delete the space in the bottom axis

  plot(1:10, axes = F, type = "n", xlim = c(0,30), ylim = c(-3,1.8))
  mtext(letters[i], side = 3, line = -1.5, adj = 0.025)

  if (i %in% c(6,7))
    axis(side = 1)

  if (i %in% c(2,4,6))
    axis(side = 2)
  box()
}
mtext("x axis", side = 1, outer = TRUE, line = 3)
mtext("y axis", side = 2, outer = TRUE, line = 3, las = 3)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明