Rosenstiel School of Marine, Atmospheric, and Earth Science and Institute for Data Science and Computing
The big picture
Remember that the final goal is to have a GitHub repository where you can showcase your work. Assignment 1 was to create the repository. Assignment two required you to develop one R script to clean some data in that same repository. For your third assignment, you visualized the data cleaned in assignment two. For your fourth assignment, you will work with spatial data to produce a map of your “study site”, broadly defined. Your final project will leverage the data and visualizations you’ll produce to wrap it all together.
This assignment
Task: Produce a map that shows a spatial aspect of your data1, and export it as a .png figure.
Your map should meet the following criteria (50% of your grade):
Additionally, your script should have the following (50% of your grade):
No Big Data on GitHub!
Spatial data can get quite large. If at any point a data file exceeds 100 MB, DO NOT PUT IT ON GITHUB. Your options are two add it to the .gitignore file (come to office hours if needed) or to make a conscious decision not to commit and push that file.
Turning in your assignment
Please share the link to your github repo via Canvas
The deadline for this assignment is Nov 16 by 23:59
Some of you were already working with data that has latitude and longitude. That is great, you can use those coordinates to build points, lines or polygons as you see fit. You may also elect to simply build a map that shows where you data came from, rather than your data themselves.
Some of you are working with data that don’t have coordinates. That is also fine, and that is often the case for most data out there. However, the data were likely collected from somewhere in the field or generated in a laboratory. You can elect to build a map of said location in a few different ways:
################################################################################# A map of my study area################################################################################## Juan Carlos Villaseñor-Derbez# jc_villasenor@miami.edu# Nov , 2025## This script loads geospatial data, wrangles it, and produces a map.################################################################################## SET UP ######################################################################## Load packages ----------------------------------------------------------------library(EVR628tools) # For fishing effort data and color paletteslibrary(ggspatial) # To add map elements to a ggplotlibrary(rnaturalearth) # To add country outlineslibrary(tidyverse) # General data wranglinglibrary(sf) # Working with vector datalibrary(terra) # Working with raster datalibrary(tidyterra) # Working with raster data in tidy approachlibrary(mapview) # To quickly inspect data# Load data --------------------------------------------------------------------# Load whale core habitatwhale <-read_sf("data/raw/shapefile_Rices_whale_core_distribution_area_Jun19_SERO/shapefile_Rices_whale_core_distribution_area_Jun19_SERO.shp")# Load depth rasterdepth <-rast("data/raw/depth_raster.tif")# Load world's coastlinecoast <-ne_countries(country =c("United States of America", "Mexico", "Belize", "Guatemala"))# Load fishing effort data.framedata("data_fishing_effort")# PROCESSING #################################################################### Create a new object to contain a raster of fishing efforteffort_raster <- data_fishing_effort |># Start with my data.framegroup_by(lon, lat) |># group by lon and latsummarize(hours =sum(effort_hours)) |># Calculate total effort by pixelrast(crs ="EPSG:4326") # Build a raster## Crop layersgulf_depth <-crop(depth, extend(effort_raster, 10))gulf_coast <-st_crop(coast, extend(effort_raster, 10))# VISUALIZE ###################################################################### Build the map ---------------------------------------------------------------p <-ggplot() +# Add the depth contours as the first laeyergeom_spatraster_contour(data = gulf_depth,aes(colour =after_stat(level)),linewidth =0.5) +# Add fishing effort raster on topgeom_spatraster(data =log(effort_raster)) +# Add gulf coast coastlinegeom_sf(data = gulf_coast,fill ="gray",color ="black") +# Add whale's core habitatgeom_sf(data = whale, fill ="transparent",color ="black",linewidth =2) +# Modify the colors for the depth contoursscale_color_viridis_c(option ="mako") +# Modify the fill of the effort rasterscale_fill_viridis_c(option ="magma",na.value ="transparent") +# Modify the themetheme_bw() +# Add a north arrow from ggspatialannotation_north_arrow(location ="tl") +# Add a scalebar from ggspatialannotation_scale(location ="bl") +# Trim whitespacescale_x_continuous(expand =c(0, 0)) +scale_y_continuous(expand =c(0, 0)) +# Update labelslabs(color ="Depth (m)",fill ="Effort [log(hours)]",x ="Longitude",y ="Latitude",title ="Fishing effort in and around Rice's whale core habitat",caption ="Data sources: NOAA Fisheries, GMED, GFW")# EXPORT ######################################################################### Export as png ---------------------------------------------------------------ggsave(plot = p,filename ="results/img/my_map.png")
Footnotes
Maybe its the study area, or your data themselves.↩︎
In the rice’s whale example, the base layers were the coastline and the depth. Our target data were the effort raster and the core habitat polygon.↩︎