library(sf)
library(tmap)
ws <- st_read("data/source/watersheds/WBDHU12.shp")
# Set tmap mode
tmap_mode("plot")
# Display polygon outlines only
tm_shape(ws) +
tm_borders()
# Display polygons with single color
tm_shape(ws)+
tm_polygons(col = "lightblue")
# Display polygons with different colors
tm_shape(ws) +
tm_polygons(col = "MAP_COLORS")
# Display polygons with color based on categorical attribute
tm_shape(ws) +
tm_polygons(col = "humod", palette = palette.colors(n = 3, "Set 2"))
# Mapping continuous variables
map <- tm_shape(ws) +
tm_polygons(col = "areaacres", n = 5, alpha = 0.5,
style = "pretty", palette = hcl.colors(n = 5, palette = "YlGnBu"), title = "area (ac)") +
tm_layout(main.title = "Watershed Area", legend.outside = T, legend.outside.size = 0.4) +
tm_scale_bar(position = c("left", "bottom")) +
tm_compass(type = "arrow", text.size = 1, size = 2, position = c("right", "bottom"))
map
tmap_save(map, "outputs/watersheds_tmap.pdf")