As a geologist, my first idea for Day 2 was faults. Not fault lines, because they’re planes that extend into the bedrock, just faults. On the map, they look like lines, and I already had this shapefile from the New York State Museum GIS archives. I’m approaching this 30 day challenge with the goal of using data I have and efficiently producing maps that fulfill the assignment. To finish putting this map together in R, I also needed raster imagery from Natural Earth.
This one turned out a little more complicated than I’d planned because I decided to crop the shaded relief imagery to the NY state boundary. My method uses the terra package to import the raster TIF and crop and mask the raster object, and tidyterra to plot in ggplot2.
Data processing code
# NYS faultsfaults <-st_read(here("posts/data/nys_faults/NYS_Faults.shp")) |>st_set_crs(st_crs("EPSG:26718")) # CRS obtained from metadata at https://data.gis.ny.gov/documents/573c1f2fe8ae43ab980b654caad03500/about# State borders from rnaturalearthstates <-st_as_sf(map("state", plot =FALSE, fill =TRUE))nys <-filter(states, ID =="new york") # Shaded relief map downloaded from Natural Earthhypso <-rast(here("posts/data/HYP_HR_SR_W_DR/HYP_HR_SR_W_DR.tif"))# Shaded relief for NYS hypso.crop <- terra::crop(hypso, extent(nys))hypso.mask <- terra::mask(hypso.crop, nys)
When I tried to render this map using Quarto, I discovered an issue with tidyterra and Quarto. I was getting an ! external pointer is not valid error, which occurred because the geom_spatraster() object is non-exportable. In order to avoid this, I set my Quarto cache to false and deleted the folder of cached files.
Plot code
ggplot() +geom_spatraster_rgb(data = hypso.mask) +geom_sf(data = faults, color ="white", alpha =0.6) +coord_sf(crs ="EPSG:26718") +labs(title ="Mapped faults in New York State")
I think this map still wants a north arrow and scale bar, but for the sake of everything else I planned to do this weekend, I’ll leave it alone.