# \donttest{
# Create a SpatVector
extfile <- system.file("extdata/cyl.gpkg", package = "tidyterra")
cyl <- terra::vect(extfile)
class(cyl)
library(ggplot2)
ggplot(cyl) +
geom_spatvector()
# With params
ggplot(cyl) +
geom_spatvector(aes(fill = name), color = NA) +
scale_fill_viridis_d() +
coord_sf(crs = 3857)
# Add labels
ggplot(cyl) +
geom_spatvector(aes(fill = name), color = NA) +
geom_spatvector_text(aes(label = iso2),
fontface = "bold",
color = "red"
) +
scale_fill_viridis_d(alpha = 0.4) +
coord_sf(crs = 3857)
# You can use now geom_sf with SpatVectors!
ggplot(cyl) +
geom_sf() +
labs(
title = paste("cyl is", as.character(class(cyl))),
subtitle = "With geom_sf()"
)
# }
Run the code above in your browser using DataLab