if (FALSE) {
library(mapboxapi)
library(tigris)
library(tmap)
library(ggspatial)
library(ggplot2)
ny_tracts <- tracts("NY", "New York", cb = TRUE)
ny_tiles <- get_static_tiles(
location = ny_tracts,
zoom = 10,
style_id = "light-v9",
username = "mapbox"
)
# tmap usage:
tm_shape(ny_tiles) +
tm_rgb() +
tm_shape(ny_tracts) +
tm_polygons(alpha = 0.5, col = "navy") +
tm_credits("Basemap (c) Mapbox, (c) OpenStreetMap",
position = c("RIGHT", "BOTTOM")
)
# ggplot2 usage:
ggplot() +
layer_spatial(ny_tiles) +
geom_sf(data = ny_tracts, fill = "navy", alpha = 0.5) +
theme_void() +
labs(caption = "Basemap (c) Mapbox, (c) OpenStreetMap")
}
Run the code above in your browser using DataLab