Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajstewartlang/58ea1c2a3278d5def03b0576f4bb3bec to your computer and use it in GitHub Desktop.
Save ajstewartlang/58ea1c2a3278d5def03b0576f4bb3bec to your computer and use it in GitHub Desktop.
SNCF_animation
library(tidyverse)
library(ggthemes)
library(tools)
library(gganimate)
library(ggimage)
full_trains <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-02-26/full_trains.csv")
p <- full_trains %>%
filter(service == "International" & year == 2017) %>%
unite(journey, departure_station, arrival_station, sep = " - ") %>%
mutate(journey = toTitleCase(tolower(journey))) %>%
mutate(month = factor(month, levels = 1:12, labels = month.name) ) %>%
mutate(image = "train.png") %>%
group_by(journey) %>%
arrange(month) %>%
mutate(cum_sum = cumsum((num_late_at_departure))) %>%
ggplot(aes(x = journey, y = cum_sum)) +
geom_image(aes(image = image), size = .15) +
guides(colour = FALSE) +
coord_flip() +
labs(title = "Running Total of International SNCF Trains Departing Late on Journeys",
subtitle = "{closest_state} 2017",
x = NULL, y = "Running Total of Trains Late at Departure") +
theme_economist() +
theme(plot.subtitle = element_text(size = 15), axis.title = element_text(size = 13), axis.text = element_text(size = 13)) +
transition_states(states = month)
animate(p, height = 500, width = 1000)
anim_save("example.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment