Module 12: Shape Files!

Author

Bryce Nelson

Part 1

Check the CRS and set if NA

st_crs(world)
Coordinate Reference System: NA
st_bbox(world)
      xmin       ymin       xmax       ymax 
-180.00000  -90.00000  180.00000   83.64513 
st_crs(world) = 4326
st_crs(world)$epsg
[1] 4326
#Plot the shp file
plot(st_geometry(world))

Plot GDP (in millions of dollars)

summary(world$gdp_md_est)
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
     -99    13160    43270   393277   232900 15094000 
world2 = world[world$gdp_md_est > 0, ]

my_breaks = c(1000,
              10000,
              100000,
              1000000,
              10000000)

ggplot() +
  geom_sf(data = world2,
          aes(fill = gdp_md_est)) +
  scale_fill_viridis(
    trans = "log",
    breaks = my_breaks,
    labels = c("$1B",
               "$10B",
               "$100B",
               "$1T",
               "$10T")) +
  theme_bw()

Plot income

ggplot() +
  geom_sf(data = world,
          aes(fill = income_grp)) +
  scale_fill_brewer(palette = "Set3") +
  theme_bw()

Part 2: Using the NDVI values you calculated in the raster section, calculate the median NDVI for Bethel Island and Oakley.

bethel = caPlaces %>% 
  dplyr::filter(NAME == "Bethel Island")

oakley = caPlaces %>% 
  dplyr::filter(NAME == "Oakley")

extract(ndvi, bethel, fun = 'median')
  ID LC08_044034_20170614_B5
1  1               0.4180438
extract(ndvi, oakley, fun = 'median')
  ID LC08_044034_20170614_B5
1  1               0.3005387