Created
April 21, 2021 08:24
-
-
Save davidsjoberg/fa6c742b4a536781dac08c36fcc6322a to your computer and use it in GitHub Desktop.
Sankey in rows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(ggsankey) | |
library(gapminder) | |
df <- gapminder %>% | |
group_by(continent, year) %>% | |
summarise(gdp = (sum(pop * gdpPercap)/1e9) %>% round(0), .groups = "keep") %>% | |
ungroup() | |
ggplot(df, aes(x = year, | |
node = continent, | |
fill = continent, | |
value = gdp, | |
shift = shift)) + | |
geom_sankey_bump(data = df %>% mutate(shift = 0), space = 1500, type = "sankey", color = "transparent", smooth = 6) + | |
geom_sankey_bump(data = df %>% mutate(shift = 70000), space = 1500, type = "sankey", color = "transparent", smooth = 6) + | |
geom_sankey_bump(data = df %>% mutate(shift = 70000*2), space = 1500, type = "sankey", color = "transparent", smooth = 6) + | |
geom_sankey_bump(data = df %>% mutate(shift = 0), space = 1500, type = "sankey", color = "transparent", smooth = 6) + | |
scale_fill_viridis_d(option = "A", alpha = .8) + | |
theme_sankey_bump(base_size = 16) + | |
labs(x = NULL, | |
y = "GDP ($ bn)", | |
fill = NULL, | |
color = NULL) + | |
theme(legend.position = "bottom") + | |
labs(title = "GDP development per continent") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment