为什么我设置的“布局”在绘制栅格图层后会丢失其配置?

问题描述

我正在为一份报告整理四张地图。我的欲望情节的设计是这样的:

enter image description here

为此,我使用 layout()plot 遵循准则 here

我在下面分享了我用来获取我提到的内容代码。注意:图 1 和图 2 的代码经过简化,以专注于我的问题。

首先,我设计我的情节安排:

## Layout design ####

layout(mat = matrix(c(1,1,2,3,4,4),ncol = 8,byrow=TRUE),widths = c(1,1),heights = c(1))
par(mar = c(0.5,0.5,0.5),oma = c(1.5,1.5,1.5))          
    
layout.show(4) # With this command we see the current plots' design,which gives the same plot I shared prevIoUsly.

然后,我开始绘制:

## Set colours for maps ####

col.t <- "#D2B48C" # Coastal line colour
col.amp <- c("darkolivegreen2","olivedrab") # Marine protected area colour
col.mar <- "lightskyblue" # Sea colour

## First plot ####

plot(1,xlim = xlim.1,ylim = ylim.1,axes = FALSE,ann = FALSE)
rect(xleft = par("usr")[1],xright = par("usr")[2],ybottom = par("usr")[3],ytop = par("usr")[4],col = col.mar,border = "transparent")
plot(coastal_line,add = TRUE,col = col.t) #shape file

## Second plot ####

plot(1,xlim = xlim.2,ylim = ylim.2,col = col.t) #shape file

## Third plot ####

plot(1,xlim = xlim.3,ylim = ylim.3,border = "transparent")

plot(bathymetry,col = fields::tim.colors(50),xlim = c(par("usr")[1],par("usr")[2]),ylim = c(par("usr")[3],par("usr")[4]),add=TRUE,legend=FALSE)  #raster file

到目前为止,一切正常,我的情节安排如下:

enter image description here

但是,当我添加等深线时,我遇到了问题:

contour(bathymetry,levels = seq(0,-80,-8))

enter image description here

如您所见,等深线绘制在我的图排列的一个小区域中(在左下角)。如果我使用 layout.show(n),我会看到当前的地块设计安排。

layout.show(16) # Here I use 16 because I checked that I had 16 plots in my layout

enter image description here

所以,我不知道为什么,但是在绘制栅格图层后,我的 layout 配置(2x2 矩阵中的 4 个图)已更改为 2x8 矩阵(=16 个图)。

有人知道为什么会这样吗?

提前致谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)