In this project, we’ll create a The Economist style visualization, a scatter plot for the relationship between the ‘Human Development Index’ and the ‘Corruption Perceptions Index’ of countries.

Setup

library(data.table)
library(ggplot2)
df <- fread(input='Economist_Data.csv',drop = 1)

head(df)
##        Country HDI.Rank   HDI CPI            Region
## 1: Afghanistan      172 0.398 1.5      Asia Pacific
## 2:     Albania       70 0.739 3.1 East EU Cemt Asia
## 3:     Algeria       96 0.698 2.9              MENA
## 4:      Angola      148 0.486 2.0               SSA
## 5:   Argentina       45 0.797 3.0          Americas
## 6:     Armenia       86 0.716 2.6 East EU Cemt Asia

A high CPI indicates a lower level of corruption.

Plot Creation

pl <- ggplot(df, aes(x=CPI,y=HDI,color=Region)) + geom_point(shape=1,size=2) 

pl

Adding a trend line:

pl2 <- pl + geom_smooth(aes(group=1), method = 'lm', formula = y~log(x), se=FALSE, color='red')

pl2