Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
draws the gganimate gapminder example, using bbc style
# packages
library(tidyverse)
library(gganimate)
library(gapminder)
library(scales)
# modified version of the bbc_style function
# adapted from: https://github.com/bbc/bbplot
bbc_style2 <- function(font = "Helvetica") {
theme(
plot.title = element_text(family = font, size = 28, face = "bold", color = "#222222"),
plot.subtitle = element_text(family = font, size = 22, margin = margin(9, 0, 9, 0)),
plot.caption = element_blank(),
legend.position = "top",
legend.text.align = 0,
legend.background = element_blank(),
legend.title = element_blank(),
legend.key = element_blank(),
legend.text = element_text(family = font, size = 18, color = "#222222"),
axis.title = element_text(family = font, size = 18, color = "#222222"),
axis.text = element_text(family = font, size = 18, color = "#222222"),
axis.text.x = element_text(margin = margin(5, b = 10)),
axis.ticks = element_blank(),
axis.line = element_blank(),
panel.grid.minor = element_blank(),
panel.grid.major.y = element_line(color = "#cbcbcb"),
panel.grid.major.x = element_blank(),
panel.background = element_blank(),
strip.background = element_rect(fill = "white"),
strip.text = element_text(size = 22, hjust = 0))
}
# gapminder animation
p <- gapminder %>%
ggplot(aes(
x = gdpPercap,
y = lifeExp,
size = pop,
colour = country)) +
geom_point(alpha = 0.7, show.legend = FALSE) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10(labels = comma) +
facet_wrap(~continent, nrow = 1) +
bbc_style2() +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
ggtitle("Year: {frame_time}") +
xlab("GDP per capita") +
ylab("Life expectancy") +
transition_time(year) +
ease_aes('linear')
# animate
animate(p, type="cairo", detail = 5, width = 1000, height = 400)
anim_save("~/../Desktop/bb_gapminder.gif")
@djnavarro

This comment has been minimized.

Copy link
Owner Author

commented Feb 26, 2019

bb_gapminder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.