Plot an invisible layer with the extent of a spatial object.

ghostLayer(x, bg)

Arguments

x

an sf object, a simple feature collection or a Spatial*DataFrame.

bg

background color.

Examples

library(sf) mtq <- st_read(system.file("gpkg/mtq.gpkg", package="cartography"))
#> Reading layer `mtq' from data source `/tmp/Rtmpe1NJW9/temp_libpathb2e69cc94c1/cartography/gpkg/mtq.gpkg' using driver `GPKG' #> Simple feature collection with 34 features and 7 fields #> geometry type: MULTIPOLYGON #> dimension: XY #> bbox: xmin: 690574 ymin: 1592536 xmax: 735940.2 ymax: 1645660 #> CRS: 32620
target <- mtq[30,] ghostLayer(target, bg = "lightblue")
plot(st_geometry(mtq), add = TRUE, col = "gold2")
plot(st_geometry(target), add = TRUE, col = "red")
# overly complicated label placement trick: labelLayer(x = suppressWarnings(st_intersection(mtq, st_buffer(target, 2000))), txt = "LIBGEO", halo = TRUE, cex = .9, r = .14, font = 2, bg = "grey20", col= "white")