Choropleth maps

Choropleth maps add color to states or countries relative to a variable.

library(pacman)
p_load(tidyverse, choroplethr, choroplethrMaps,RColorBrewer)

State Population

data(df_pop_state)
pop_state <- df_pop_state %>% arrange(-(value))
top_n(pop_state,10)
## Selecting by value
state_choropleth(df_pop_state, 
                 title  = "US 2012 State Population Estimates", 
                 legend = "Population")

County Population

data(df_pop_county)
county_choropleth(df_pop_county,
                 title  = "US 2012 County Population Estimates", 
                 legend = "Population", num_colors = 8)

California Counties

county_choropleth(df_pop_county, 
                  title = "California County Population Estimates", 
                  legend = "Population",
                  state_zoom = "california")

State Demographics

data("df_state_demographics")
head(df_state_demographics,10)
# African American Population Distribution
df_state_demographics$value<- df_state_demographics$percent_black
state_choropleth(df_state_demographics, 
                 title  = "African American Population Distribution in US", 
                 legend = "Population")

# White Population Distribution
df_state_demographics$value<- df_state_demographics$percent_white
state_choropleth(df_state_demographics, 
                 title  = "White Population Distribution in US", 
                 legend = "Population")

# Asian Population Distribution
df_state_demographics$value<- df_state_demographics$percent_asian
state_choropleth(df_state_demographics, 
                 title  = "Asian Population Distribution in US", 
                 legend = "Population")

World Map

data("df_pop_country")
country_pop <- df_pop_country %>% arrange(desc(value))
head(country_pop,10)
country_choropleth(country_pop, 
                 title  = "World map based on population estimates", 
                 legend = "Population")
## Warning in self$bind(): The following regions were missing and are being set to
## NA: namibia, western sahara, taiwan, antarctica, kosovo

Heatmap

Heatmaps visual the values in a matrix by adding color relative to a variable(s), usually down columns.

data(df_state_demographics)
df_state_demographics <- df_state_demographics %>% arrange(total_population)

X <- data.matrix(df_state_demographics[,2:8])

row.names(X) <- df_state_demographics[,1]

head(X)
##                      total_population percent_white percent_black percent_asian
## wyoming                        570134            85             1             1
## district of columbia           619371            35            49             3
## vermont                        625904            94             1             1
## north dakota                   689781            88             1             1
## alaska                         720316            63             3             5
## south dakota                   825198            84             1             1
##                      percent_hispanic per_capita_income median_rent
## wyoming                             9             28902         647
## district of columbia               10             45290        1154
## vermont                             2             29167         754
## north dakota                        2             29732         564
## alaska                              6             32651         978
## south dakota                        3             25740         517
heatmap(X, Rowv=NA, Colv=NA, col = brewer.pal(9, "Blues"), scale = "column")