Instructions

Answer the following questions and complete the exercises in RMarkdown. Please embed all of your code and push your final work to your repository. Your final lab report should be organized, clean, and run free from errors. Remember, you must remove the # for the included code chunks to run. Be sure to add your name to the author header above. For any included plots, make sure they are clearly labeled. You are free to use any plot type that you feel best communicates the results of your analysis.

Make sure to use the formatting conventions of RMarkdown to make your report neat and clean!

Load the libraries

library(tidyverse)
library(janitor)
library(ggmap)
library(leaflet)

API Key

register_stadiamaps("YOUR API KEY HERE", write = FALSE)

Load the Data

For this homework, we will use the shark attack data to visualize where the attacks occurred. The data are from: State of California- Shark Incident Database.

sharks <- read_csv("data/SharkIncidents_1950_2022_220302.csv") %>% 
  clean_names() %>% 
  filter(longitude !="NA" & latitude !="NA") %>% # pulling out NA locations
  mutate(longitude = as.numeric(longitude)) # converting longitude to numeric
  1. Use the range of the latitude and longitude to build an appropriate bounding box for your map.

  2. Load a map from stamen in a terrain style projection and display the map.

  3. Build a map that overlays the recorded observations of shark attacks in California.

  4. Build a map that only shows the fatalities.

  5. Build the same map (fatalities only), but this time make it interactive using leaflet. Also, color the points red.

  6. Which county has the highest number of recorded shark attacks? Make a map that only shows the attacks in this county. (hint: it may help improve the map if you remove duplicate locations, i.e. multiple attacks at the same location.)

Knit and Upload

Please knit your work as an .html file and upload to Canvas. Homework is due before the start of the next lab. No late work is accepted. Make sure to use the formatting conventions of RMarkdown to make your report neat and clean!