Skip to content

Instantly share code, notes, and snippets.

@Fahim-Ahmad
Created March 7, 2021 05:44
Show Gist options
  • Save Fahim-Ahmad/c61bc9118e038c3d05e25060a3d057b9 to your computer and use it in GitHub Desktop.
Save Fahim-Ahmad/c61bc9118e038c3d05e25060a3d057b9 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(patchwork)
theme_set(theme_bw())
plot_1 <- gapminder::gapminder %>%
filter(year == max(year)) %>%
group_by(continent) %>%
summarize(mean = mean(gdpPercap)) %>%
ungroup() %>%
ggplot(aes(x = continent, y = mean, fill = continent)) +
geom_col(show.legend = F, alpha = 0.7) +
geom_text(aes(label = round(mean)), vjust = 1) +
theme(axis.text.x = element_blank(), axis.ticks.x = element_blank()) +
labs(x = NULL, y = NULL)
plot_2 <- gapminder::gapminder %>%
filter(year == max(year)) %>%
ggplot(aes(x = gdpPercap, fill = continent)) +
geom_density(alpha = 0.5) +
theme(legend.position = "top") +
labs(y = NULL,
x = paste0("GDP per capita (US$, inflation-adjusted) - ",
max(gapminder::gapminder$year)),
fill = NULL)
plot_2 + inset_element(plot_1,
left = 0.5, bottom = 0.4, right = 1, top = 0.85,
align_to = "full")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment