library("plyr")
pkgs <- c("tidyverse", "janitor", "stats", "broom","readxl", "gganimate", "gifski", "png", "transformr", "magick", "ggpomological")
l_ply(pkgs,library,character.only=TRUE)
UN2017 <- read_excel("UN2017.xlsx", col_names=TRUE)
head(UN2017)
## # A tibble: 6 x 6
## country code gdp hdi region nshemi
## <chr> <chr> <dbl> <dbl> <chr> <chr>
## 1 Afghanistan AFG 556. 0.498 Asia Pacific South
## 2 Albania ALB 4533. 0.785 Europe North
## 3 Algeria DZA 4048. 0.754 Arab States South
## 4 Andorra AND 39134. 0.858 Europe North
## 5 Angola AGO 4096. 0.581 Africa South
## 6 Antigua_Barbuda ATG 15825. 0.78 Latin and South America South
boots <- ungeviz::bootstrapper(20, nshemi)
ggplot(UN2017, aes(gdp, hdi, color = nshemi)) +
geom_smooth(method = "lm", color = NA) +
geom_point(alpha = 0.3) +
geom_point(data = boots, aes(group = .row)) +
geom_smooth(data = boots, method = "lm", fullrange = TRUE, se = FALSE) +
facet_wrap(~nshemi, scales = "free_x") +
scale_color_manual(values = c(North = "#D55E00", South = "#0072B2"), guide = "none") +
theme_bw() +
transition_states(.draw, 1, 1) +
enter_fade() +
exit_fade()

ggplot(UN2017, aes(gdp, hdi, color = nshemi)) +
geom_smooth(method = "lm", color = NA) +
geom_point(alpha = .1) +
geom_point(data = boots, aes(group = .row)) +
geom_smooth(data = boots, method = "lm", fullrange = TRUE, se = FALSE) +
facet_wrap(~nshemi, scales = "free_x") +
scale_color_pomological() +
labs(title = "Visualizing uncertainty with gganimate",
x = "Gross Domestic Product (US$)",
y = "Human Development Index",
colour = "Hemisphere") +
theme_pomological() +
theme(legend.position="none") +
transition_states(.draw, 2, 0.000002) +
enter_fade() +
exit_fade()
