• A common type of vector data is data with multiple polygons that each have associated properties
  • For Harvard Forest we have a map of soil types at the site
  • Let’s load it and map it using the sf package
library(sf)

harv_soils <- read_sf("data/harv/harv_soils.shp")

ggplot() +
  geom_sf(data = harv_soils)
  • We can see that we get a map with multiple polygons
  • If we look at the harv_soils object we’ll see that it’s a simple feature object with the geometry being POLYGON
harv_soils
  • Each feature is a single polygon with 5 associated fields: soil type, notes, two different soil type descriptions, and how well drained the soil is
  • We can include this information on our maps in the same ways we include it in other ggplot maps and graphs
  • Let’s start by coloring each polygon by it’s soil type
  • We do this by setting the mapping to have fill = TYPE_
ggplot() +
  geom_sf(data = harv_soils, mapping = aes(fill = TYPE_))
  • We can switch the color scheme to viridis like we did for raster data, but using the _d for discrete
ggplot() +
  geom_sf(data = harv_soils, mapping = aes(fill = TYPE_)) +
  scale_fill_viridis_d()
  • We can also plot different soil types on different subplots to help us focus on where individual soil types occur
  • We do this using facet_wrap just like we did for plotting tabular data
ggplot() +
  geom_sf(data = harv_soils) +
  facet_wrap(~TYPE_)
  • This might be more useful in the context of the boundary so we could add the boundary as another layer
harv_boundary <- read_sf("data/harv/harv_boundary.shp")
ggplot() +
  geom_sf(data = harv_boundary) +
  geom_sf(data = harv_soils, fill = "blue") +
  facet_wrap(~TYPE_)

Do Tasks 1 & 2 of Harvard Forest Soils Analysis.