# NOT RUN {
# Create a SpatVector
extfile <- system.file("extdata/cyl.gpkg", package = "tidyterra")
cyl <- terra::vect(extfile)
class(cyl)
#' # Create a SpatVector
extfile <- system.file("extdata/cyl.gpkg", package = "tidyterra")
cyl <- terra::vect(extfile)
class(cyl)
library(ggplot2)
ggplot() +
geom_spatvector(data = cyl)
# Avoid this!
if (FALSE) {
# Would produce an error
ggplot(cyl) +
geom_spatvector()
}
# With params
ggplot() +
geom_spatvector(data = cyl, aes(fill = name), color = NA) +
scale_fill_viridis_d() +
coord_sf(crs = 3857)
# Add labels
ggplot() +
geom_spatvector(data = cyl, aes(fill = name), color = NA) +
geom_spatvector_text(
data = cyl, aes(label = iso2), fontface = "bold", size = 3,
color = "red"
) +
scale_fill_viridis_d(alpha = 0.4) +
coord_sf(crs = 3857)
# }
Run the code above in your browser using DataLab