5.1 Plot methods for sp objects

Let’s first get some data:

library(sp)
library(sf)
library(raster)
bel1 <- getData("GADM", country = "BEL", level = 1, path =  "data")
#R>  Warning in getData("GADM", country = "BEL", level = 1, path = "data"): getData will be removed in a future version of raster
#R>  . Please use the geodata package instead
bel2 <- getData("GADM", country = "BEL", level = 2, path =  "data")
#R>  Warning in getData("GADM", country = "BEL", level = 2, path = "data"): getData will be removed in a future version of raster
#R>  . Please use the geodata package instead

Quick plot:

plot(bel1)

Two quick plots:

par(mfrow = c(1, 2), mar = c(0, 0, 0, 0))
plot(bel1, col = 1:3)
plot(bel2, lty = 2)

Slightly customized plots:

plot(bel1, col = "grey85", main = "Belgium")
plot(bel2, lwd = .5, add = TRUE)
points(coordinates(bel2), pch = 19, cex = .4)
city <- coordinates(bel2)[1, ]
text(city[1], city[2], labels = "Bruxelles", pos = 3, col = "#9728eb")