Skip to content

Instantly share code, notes, and snippets.

@timwaterhouse
Last active January 29, 2020 08:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timwaterhouse/6606bb5953b18acba88224d0b248b978 to your computer and use it in GitHub Desktop.
Save timwaterhouse/6606bb5953b18acba88224d0b248b978 to your computer and use it in GitHub Desktop.
gganimate CV
library(ggplot2)
library(tidyr)
library(dplyr)
library(maps)
library(gganimate)
WorldData <- map_data('world')
#WorldData %>% filter(region != "Antarctica") -> WorldData
WorldData <- fortify(WorldData)
n_pause <- 3 # number of rows to pause at each step
bounds <- tribble(
~country, ~xmin, ~xmax, ~ymin, ~ymax,
"world", -180, 190, -58.5, 83.6,
"australia", 130, 170, -43, -11,
"uk", -12, 6, 50, 60,
"usa", -90, -55, 30, 50,
)
cities <- tribble(
~city, ~latitude, ~longitude,
"townsville", -19.256389, 146.818333,
"brisbane", -27.466667, 153.033333,
"canberra", -35.293056, 149.126944,
"southampton", 50.9, -1.4,
"indianapolis", 39.791, -86.148,
"tariffville", 41.908333, -72.763889
)
steps <- tribble(
~country, ~city, ~label,
"world", "townsville", "Buffering...",
"australia", "brisbane", "1995-1999:\nUniversity of Queensland\nBSc (Maths & Stats)",
"australia", "canberra", "2000-2001:\nAustralian Bureau of Statistics\nSurvey Design",
"australia", "brisbane", "2001-2005:\nUniversity of Queensland\nPhD (Optimal Design)",
"uk", "southampton", "2005-2006:\nUniversity of Southampton\nPostdoc (Optimal Design)",
"usa", "indianapolis", "2006-2019:\nEli Lilly & Co\nPK/PD M&S",
"usa", "tariffville", "2019-Present:\nMetrum Research Group\nPK/PD M&S",
"world", "tariffville", NULL
) %>%
left_join(bounds, by = "country") %>%
left_join(cities, by = "city") %>%
slice(rep(1:n(), each = n_pause)) %>%
mutate(
step = row_number()
) %>%
identity() # useful for testing bits of dplyr chain
anim <- ggplot(steps) +
geom_map(data = WorldData, map = WorldData,
aes(group = group, map_id = region),
fill = "white", colour = "#7f7f7f", size = 0.5) +
geom_line(aes(x = longitude, y = latitude)) +
geom_point(aes(x = longitude, y = latitude), size = 2, colour = "blue") +
geom_label(aes(x = longitude, y = latitude, label = label),
colour = "blue", size = 8, vjust = 0.5, nudge_y = 5) +
theme(
axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank()
) +
transition_reveal(step) +
view_zoom_manual(
pause_length = 1,
step_length = 8,
xmin = steps$xmin,
xmax = steps$xmax,
ymin = steps$ymin,
ymax = steps$ymax,
#wrap = FALSE,
#ease = "linear",
aspect_ratio = 1) +
ease_aes("sine-in-out") +
coord_fixed(ratio = 1) +
NULL
animate(anim, duration = 15, fps = 15)
#animate(anim, duration = 5, fps = 5)
anim_save("cv.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment