[You do not have to include any graphs here, but you can for your own notes if you wish!]
lab11_theme = theme_bw() +
theme(text = element_text(family = "serif", size = 12))
data(temp_carbon)
temp_anomaly = temp_carbon %>%
select(Year = year, Global = temp_anomaly, Land = land_anomaly, Ocean = ocean_anomaly) %>%
pivot_longer(Global:Ocean, names_to = "Region", values_to = "Anomaly") %>%
filter(!is.na(Anomaly))
temp_anomaly %>%
ggplot(aes(x = Year, y = Anomaly, col = Region)) +
geom_line(size = 1) +
geom_hline(aes(yintercept = 0), lty = 2) +
annotate("text", x = 2005, y = -.08,
label = "20th century mean", size = 3) +
scale_color_viridis_d(option = "C", end = .75) +
labs(
title = "Temperature anomaly relative to 20th century mean",
x = "Year",
y = "Temperature anomaly (degrees C)"
) +
lab11_theme
anim_1 = temp_anomaly %>%
ggplot(aes(x = Year, y = Anomaly, col = Region)) +
geom_line(size = 1) +
geom_hline(aes(yintercept = 0), lty = 2) +
annotate("text", x = 2005, y = -.08,
label = "20th century mean", size = 3) +
scale_color_viridis_d(option = "C", end = .75) +
labs(
title = "Temperature anomaly relative to 20th century mean",
x = "Year",
y = "Temperature anomaly (degrees C)"
) +
lab11_theme +
transition_reveal(Year)
animate(anim_1, nframes = 10)
anim_2 = temp_anomaly %>%
ggplot(aes(x = Year, y = Anomaly, col = Region)) +
geom_line(size = 1) +
geom_segment(aes(xend = 2030, yend = Anomaly), linetype = 2) +
geom_text(aes(x = 2030, label = Region), hjust = 0) +
geom_hline(aes(yintercept = 0), lty = 2) +
annotate("text", x = 2005, y = -.08,
label = "20th century mean", size = 3) +
scale_color_viridis_d(option = "C", end = .75) +
labs(
title = "Temperature anomaly relative to 20th century mean",
x = "Year",
y = "Temperature anomaly (degrees C)"
) +
xlim(1880, 2040) +
coord_cartesian(clip = 'off') +
lab11_theme +
guides(col = FALSE) +
transition_reveal(Year)
animate(anim_2, nframes = 10)
animate(anim_2, nframes = 150)
data(temp_carbon)
temp_anomaly = temp_carbon %>%
select(Year = year, Global = temp_anomaly, Land = land_anomaly, Ocean = ocean_anomaly) %>%
pivot_longer(Global:Ocean, names_to = "Region", values_to = "Anomaly") %>%
filter(!is.na(Anomaly))
anim_1 = temp_anomaly %>%
ggplot(aes(x = Year, y = Anomaly, col = Region)) +
geom_line(size = 1) +
geom_hline(aes(yintercept = 0), lty = 2) +
annotate("text", x = 2005, y = -.08,
label = "20th century mean", size = 3) +
scale_color_viridis_d(option = "C", end = .75) +
labs(
title = "Temperature anomaly relative to 20th century mean",
x = "Year",
y = "Temperature anomaly (degrees C)"
) +
theme_minimal() +
transition_reveal(Year)
animate(anim_1, nframes =10)
[You do not have to include any graphs here, but you can for your own notes if you wish!]
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_wide = covid %>%
pivot_wider(., id_cols = c(geo_value, time_value), names_from = signal, values_from = value)
covid_wide %>%
ggplot(aes(x = smoothed_wearing_mask, y = smoothed_restaurant_1d, size = smoothed_cli)) +
geom_point()
covid_wide %>%
filter(time_value == "2020-10-31") %>%
ggplot(aes(x = smoothed_wearing_mask, y = smoothed_restaurant_1d, size = smoothed_cli, col = smoothed_cli)) +
geom_point(alpha = .5) +
scale_color_viridis_c(option = "C", end = .75) +
lab11_theme +
theme(legend.position = "bottom")
anim_3 = covid_wide %>%
ggplot(aes(x = smoothed_wearing_mask, y = smoothed_restaurant_1d, size = smoothed_cli, col = smoothed_cli)) +
geom_point(alpha = .5) +
scale_color_viridis_c(option = "C", end = .75) +
lab11_theme +
theme(legend.position = "bottom") +
transition_time(time_value)
animate(anim_3, nframes = 10)
anim_4 = covid_wide %>%
ggplot(aes(x = smoothed_wearing_mask, y = smoothed_restaurant_1d, size = smoothed_cli, col = smoothed_cli)) +
geom_point(alpha = .5) +
scale_color_viridis_c(option = "C", end = .75, guide = "legend") +
lab11_theme +
theme(legend.position = "bottom") +
transition_time(time_value) +
shadow_mark(size = .1, alpha = .1) +
labs(
title = "Restaurant visits, mask-wearing, and COVID-like illness over time",
subtitle = 'Date: {frame_time}',
x = "% Wearing Mask in Public",
y = "% Visited Restaurant",
col = "% with COVID-like Illness",
size = "% with COVID-like Illness",
caption = "Source: CMU Delphi Symptom Survey"
)
animate(anim_4, nframes = 10)
animate(anim_4, nframes = 100)
Using any data besides gapminder, create any animation you want (besides the ones I’ve included here). Your animations can be similar to Examples 1 and 2, but should include changes beyond plugging in different variables to the aes calls.
Everybody should submit an .rmd file with your animation. You should also turn in an HTML document (via RPubs) or use anim_save() to save your animation and turn it in alongside your .rmd file:
anim_save(FILENAME, animation = last_animation())
(for more info, use ?anim_save)
covid_wide_small <- subset(covid_wide, geo_value == "pa" | geo_value == "nj")
#added points using geom_point and we sequence it along time_value
anim_5 = covid_wide_small %>%
ggplot(aes(x = time_value, y = smoothed_anxious_5d, col = geo_value)) +
geom_line(size = 1) +
geom_text(x=as.Date("2020-12-30"),aes(label = geo_value), hjust = 2) +
geom_segment(aes(xend=as.Date("2020-12-31"),yend=smoothed_anxious_5d),linetype=2)+
scale_color_viridis_d(option = "C", end = .75) +
labs(
title = "Feeling Anxious By State",
x = "Time",
y = "% Feeling Anxious over the last 5 Days"
) +
coord_cartesian(clip = 'off') +
guides(col = FALSE) +
geom_point(aes(group = seq_along(time_value)))+
transition_reveal(time_value) +
lab11_theme
animate(anim_5, nframes = 10)