Plotly Graph

## Change this to read in whatever data you're using
covid = read_csv("covid_data.csv")
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   signal = col_character(),
##   geo_value = col_character(),
##   time_value = col_date(format = ""),
##   value = col_double(),
##   stderr = col_double(),
##   sample_size = col_double()
## )
covid %>%
  group_by(geo_value, signal) %>%
  summarize(
    avg = mean(value, na.rm = T)
  ) %>%
  pivot_wider(id_cols = geo_value, names_from = signal, values_from = avg) %>%
  ungroup() -> state_avg
## `summarise()` has grouped output by 'geo_value'. You can override using the `.groups` argument.
## Change this to make your plot

p1 = state_avg %>%
  mutate(state = str_to_upper(geo_value)) %>%
  ggplot(aes(x = smoothed_wearing_mask, y = smoothed_cli)) +
  geom_point() +
  theme_minimal() 

ggplotly(p1)
p2 = state_avg %>%
    mutate(state = str_to_upper(geo_value)) %>%
    ggplot(aes(x = smoothed_wearing_mask, y = smoothed_cli)) +
    geom_point(aes(text = toupper(geo_value))) + 
    theme_minimal()
## Warning: Ignoring unknown aesthetics: text
ggplotly(p2, tooltip = "text")

Part 2: Plotly Graph From Previous Labs

lab09_theme = theme_minimal() +
  theme(text = element_text(family = "serif", size = 12))

pa_tested = covid %>%
  filter(signal == "smoothed_tested_14d" & geo_value == "pa")

pa_tested
## # A tibble: 92 x 6
##    signal              geo_value time_value value stderr sample_size
##    <chr>               <chr>     <date>     <dbl>  <dbl>       <dbl>
##  1 smoothed_tested_14d pa        2020-10-01  6.17  0.224      11505.
##  2 smoothed_tested_14d pa        2020-10-02  6.17  0.223      11622.
##  3 smoothed_tested_14d pa        2020-10-03  6.12  0.223      11558.
##  4 smoothed_tested_14d pa        2020-10-04  6.09  0.222      11564.
##  5 smoothed_tested_14d pa        2020-10-05  6.11  0.223      11588.
##  6 smoothed_tested_14d pa        2020-10-06  6.04  0.219      11817.
##  7 smoothed_tested_14d pa        2020-10-07  6.14  0.217      12279.
##  8 smoothed_tested_14d pa        2020-10-08  6.09  0.215      12423.
##  9 smoothed_tested_14d pa        2020-10-09  6.11  0.215      12443.
## 10 smoothed_tested_14d pa        2020-10-10  6.16  0.216      12379.
## # … with 82 more rows
p3 <- ggplot(pa_tested, aes(x = time_value, y = value)) +
  geom_rect(data = pa_tested, aes(xmin = as.Date("2020-11-26") - 14, xmax = as.Date("2020-11-26"), ymin = value - 2*stderr, ymax = value + 2*stderr)) +
  geom_line() +
  lab09_theme + 
  labs(
    x = "",
    y = "",
    title = "% of Pennsylvanians who were tested for COVID over previous 14 days",
    subtitle = "Smoothed Estimate",
    caption = "Source: Delphi Symptom Survey"
  )
  
moving_things <- ggplotly(p3)

moving_things