9.4 Creating a simple layout

my.layout <- layout(matrix(1:2, 2), heights = c(1, .14))
layout.show(my.layout)

mar controls the margins of the plot area;

xaxs and yaxs controls axis style.

library(RColorBrewer)

layout(matrix(1:2, 2), heights = c(1, .16))
par(las = 1, xaxs = "i", yaxs = "i", mar = rep(c(2.5, 3), 2))

myblu <- "#6da6c2"
mygre <- "grey50"
mypal <- colorRampPalette(rev(brewer.pal(11, "RdYlBu")))(124)

plot(st_geometry(qc_neigh_simple),
  graticule = st_crs(qc_simple), # add graticules
  col = "#b5cfbd", border = mygre,
  xlim = c(-82, -56), ylim = c(43, 64)
)
plot(st_geometry(usa0_simple), col = "#b5cfbd", border = mygre, add = TRUE)

# Temperature raster
image(temp_mask, add = TRUE, col = mypal)

# Quebec boundary on top
plot(st_geometry(qc_simple), add = TRUE, col = NA, border = "grey15", lwd = 1.4)

# Sample points
plot(st_geometry(sample_pts),
  add = T, pch = 21,
  bg = "#63636388", col = "grey15", lwd = 1.4,
  cex = sample_richness / 25
) # Size proportional to richness

# Axis
axis(1)
axis(2, las = 1)
axis(3)
axis(4, las = 1)
box(lwd = 1.2)

# Compass rose
sp::compassRose(-57, 60)

# Legend
par(mar = c(3.2, 5, .5, 5), mgp = c(2, .5, 0))

val <- range(values(temp_mask), na.rm = TRUE)
image(as.matrix(seq(val[1], val[2], length = 512)), col = mypal, axes = FALSE)
axis(1, at = seq(0.001, .999, length = 6), labels = round(seq(val[1], val[2], length = 6), 2))
mtext(side = 1, line = 1.8, text = "Mean annual temperature (°C)")