Static
lab11_theme = theme_minimal()
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_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 = 150)
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 %>%
# 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_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 = 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)
AAPL <- tq_get("AAPL",
from = "2020-01-01",
to = "2020-12-30",
get = "stock.prices")
apple_trades <- df %>% filter(ticker == "AAPL")
apple_trades$date <- as.Date(apple_trades$transaction_date, "%m/%d/%Y")
apple_trades <- apple_trades %>% filter(date > "2020-01-01")
apple_trades <- left_join(apple_trades, AAPL, by = c("date" = "date"))
apple_trades <- apple_trades%>%select(-c(comment))
anim_5 <- AAPL %>%
ggplot(aes(x = date, y = adjusted)) +
geom_line() +
labs(title = "Apple Close Price 2020 w/ Senate Purchases", y = "Closing Price", x = "") +
scale_color_manual(
"legend",
values = c(
"Sale (Full)" = "#FF5000",
"Purchase" = "#00C805",
"Sale (Partial)" = "#F4A261"
)
) +
theme_minimal() +
theme(legend.position = "none", axis.title.x = element_blank()) +
geom_point(
shape = 22,
data = apple_trades,
aes(
# x = date,
# y = adjusted,
color = action,
size = max_value,
group=seq_along(date)
),
)+
transition_reveal(date) +
view_follow(fixed_y=c(60, NA))+
shadow_mark(past=TRUE)
animate(anim_5, nframes = 100)