5.4 plotting together sf and raster objects

# Create a new color palette
library(RColorBrewer)
myPal <- brewer.pal(n = 9, name = "Greens")

# Plot the altitude raster
plot(alt,
  col = myPal,
  xlab = "Longitude",
  ylab = "Latitude")

# Add Belgium boundary map
plot(st_geometry(bel2_sf), add = TRUE)

# Add a point at the centroid of Bruxelles
brux <- bel2_sf[bel2_sf$NAME_1 == "Bruxelles",]

plot(st_geometry(st_centroid(brux)), pch = 20, add = TRUE)
#R>  Warning in st_centroid.sf(brux): st_centroid assumes attributes are constant
#R>  over geometries of x
# Add a label for Bruxelles on the map
text(st_coordinates(st_centroid(brux)), labels = "Bruxelles", pos = 3, col = "#9728eb")
#R>  Warning in st_centroid.sf(brux): st_centroid assumes attributes are constant
#R>  over geometries of x