Using R and GGPlot to Map Inequality

rm(list = ls())


US_GINI_Data <- read.csv("US Census Data Intra-US GINI/ACS_15_1YR_B19083_with_ann.csv")

suppressMessages(library(rgeos))
library(ggplot2)
library(rgeos)
library(plyr)
library(scales)
require(graphics)
library(ggthemes)
library(colorspace)

# read csv
US_GINI_Data <- read.csv("US Census Data Intra-US GINI/ACS_15_1YR_B19083_with_ann.csv")

# state data
states_map <- map_data("state")

# Let's give better names
colnames(US_GINI_Data) <- c("GEO.id", "GEO.id2", "state", "GINI", "GINI2")

# change to lower case
gini <- as.data.frame(lapply(US_GINI_Data, tolower), stringsAsFactors = FALSE)
# we have to trasform GINI to num
gini <- transform(gini, GINI = as.numeric(GINI))

# megre map data and GINI data
gini_map <- merge(states_map, gini, by.x = "region", by.y = "state")

# create map, g
g <- ggplot(data=gini_map, mapping = aes(x=long, y=lat, group=group))+
  geom_polygon(aes(fill=GINI))+
  geom_path() + coord_map("mercator")

remove_axes <- theme(
  axis.text = element_blank(),
  axis.line = element_blank(),
  axis.ticks = element_blank(),
  panel.border = element_blank(),
  panel.grid = element_blank(),
  axis.title = element_blank()
)
# add title
g <- g+remove_axes+ggtitle('GINI Accross the United States')
# change data color encoding
g <- g+scale_fill_distiller(name="GINI", palette = "YlGn", breaks = pretty_breaks(n = 5))

# print graph
g

The above choropleth shows the GINI level within the United States, differentiated by State. The lighter the color fill, the higher the GINI. GINI is measured on a 0 to 1 scale, where 0 is a theoretically equal income distribution. While 1 represents a society where all the income is controlled by a single holder.

We can use R to gain more information on the GINI distribution between U.S. States, for example:

summary(gini)
##     GEO.id            GEO.id2             state                GINI       
##  Length:52          Length:52          Length:52          Min.   :0.4252  
##  Class :character   Class :character   Class :character   1st Qu.:0.4523  
##  Mode  :character   Mode  :character   Mode  :character   Median :0.4666  
##                                                           Mean   :0.4675  
##                                                           3rd Qu.:0.4797  
##                                                           Max.   :0.5589  
##     GINI2          
##  Length:52         
##  Class :character  
##  Mode  :character  
##                    
##                    
## 

This analysis shows us the minimum U.S. State GINI, as well as the maximum. Furthermore, we can see the mean U.S. GINI is 0.4675, while the median is 0.466. Of course, this is different from the U.S. GINI coefficent.

References

U.S. Census Bureau, 2014 American Community Survey 1-Year Estimates