Skip to content

Instantly share code, notes, and snippets.

@favstats
Last active August 2, 2022 07:53
Show Gist options
  • Save favstats/df54246d42438c553efbba4e93f879e2 to your computer and use it in GitHub Desktop.
Save favstats/df54246d42438c553efbba4e93f879e2 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(rvest)
library(ggpubr)
library(COVID19)
## 1st step:
# go to http://www.sharkattackdata.com/place/united_states_of_america
## 2nd step:
# save HTML file to same location as script
## 3rd step:
# run script below
## Load Data
sharks_dat <- read_html("Shark Attack Data_ United States of America.html") %>%
html_table() %>%
.[[1]]
sharks_dat <- sharks_dat %>%
.[,1:2] %>%
count(Area, sort = T)
## get covid19 data on state level
covdat <- covid19("US", level = 2)
covdat %>%
arrange(desc(date)) %>%
group_by(administrative_area_level_2) %>%
slice(2) %>%
left_join(sharks_dat %>% rename(administrative_area_level_2 = Area)) %>%
ggplot(aes(n, confirmed)) +
geom_point() +
geom_smooth(method = "lm", se = F, color = "red") +
theme_minimal() +
labs(y = "Confirmed COVID-19 Cases (per State)\n", x = "\nNumber of Unprovoked and Provoked Shark Attacks since 1900 (per State)") +
ggpubr::stat_cor()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment