Skip to content

Instantly share code, notes, and snippets.

@gabrielzanlorenssi
Created October 21, 2019 18:01
Show Gist options
  • Save gabrielzanlorenssi/372675291750e9123d378b88a097affb to your computer and use it in GitHub Desktop.
Save gabrielzanlorenssi/372675291750e9123d378b88a097affb to your computer and use it in GitHub Desktop.
library(readxl)
library(tidyverse)
library(ggrepel)
# Data -------------------------------------------------------------------
# data here https://docs.google.com/spreadsheets/d/11bv5VB6Hyz0BeWBWPiVoE-mlvOm9kB6jbCHGdjaz27Q/edit?usp=sharing
gini <- read_excel("~/Downloads/gini.xlsx", sheet="Sheet4")
# Plot -------------------------------------------------------------------
gini %>%
ggplot(aes(x=GDP, y=Gini)) +
geom_point(aes(col=Democracy)) +
ggrepel::geom_text_repel(aes(label=TableName), size=3.3) +
geom_vline(xintercept = median(gini$GDP, na.rm=T)) +
geom_hline(yintercept = median(gini$Gini, na.rm=T)) +
scale_x_log10(labels=scales::comma) +
labs(title="GDP per capita and inequality in high income countries",
x="GDP per capita (PPP) in log10 scale",
y="Gini",
caption = "Sources include World Bank, The Economist, CIA Factbook and academic studies. \n
Some small countries were excluded. Latest year for Gini, 2018 for Democracy Index and 2016 for GDP") +
theme_minimal(base_size = 18) +
theme(legend.position = "bottom", legend.box="horizontal") +
theme(panel.grid = element_line(linetype = "dashed",
size = 0.1,
colour = "black")) +
theme(text = element_text(family = "Bebas Neue")) +
theme(axis.line = element_line(size=0.2)) +
theme(plot.title = element_text(hjust = 0.5)) +
scale_color_manual(values= c("#FF3400", "#A60CE8", "#EBB605"), na.value="gray50", "The Economist Democracy Index") +
theme(plot.caption = element_text(family="Arial", size=8))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment