【问题标题】:How to adjust the margins of a single plot inside a layout in R?如何调整 R 布局内单个绘图的边距?
【发布时间】:2017-11-23 19:23:11
【问题描述】:

我有一个由 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)

我想要类似的东西

【问题讨论】:

    标签: r layout plot margins par


    【解决方案1】:

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

    par(mar = c(2.5,0,0,0))
    

    然后,从for 开始删除这个边距

    par(mar = c(0,0,0,0))
    

    完整代码:

    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)
    

    【讨论】:

      猜你喜欢
      • 2021-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-18
      • 2011-08-26
      • 1970-01-01
      相关资源
      最近更新 更多