Plotly Graph
## Change this to read in whatever data you're using
covid = read_csv("covid_data.csv")
## Parsed with 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()` regrouping output by 'geo_value' (override with `.groups` argument)
## Change this to make your plot
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")
abbrev <- read_csv("./states.csv")
## Parsed with column specification:
## cols(
## State = col_character(),
## Abbrev = col_character(),
## Code = col_character()
## )
travel <-
covid %>% filter(signal == "smoothed_travel_outside_state_5d",
time_value == "2020-10-01")
travel$Code <- toupper(travel$geo_value)
travel <- left_join(travel, abbrev)
## Joining, by = "Code"
travel$region <- tolower(travel$State)
us_states <- map_data("state")
df <- left_join(travel, us_states)
## Joining, by = "region"
p0 <- ggplot(data = df,
mapping = aes(
x = long,
y = lat,
group = group,
fill = value
))
p1 <- p0 + geom_polygon(color = "gray90", size = 0.1) +
coord_map(projection = "albers",
lat0 = 39,
lat1 = 45)
p2 <-
p1 + scale_fill_gradient2(low = "yellow", high = "red") + labs(title = "Percent of Respondants Travelling on 2020-10-01")
p2 <- p2 + theme_map() + labs(fill = "Percent")
ggplotly(p2)