Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alaska and Hawaii not formatting correctly for County Choropleth Map in R

I am trying to format a Choropleth Map of the United States to a specific color and unfortunately, when using scale_fill_brewer to change the color; only 48 of the states do (Hawaii and Alaska do not). Is it possible to know if I can implement the coloring to Hawaii and Alaska as well?

library(choroplethr) 
library(choroplethrMaps)
library(ggplot2) 
data(df_pop_county)

county_choropleth(df_pop_county, title = "Title1", legend = "Top 20% of Index", num_colors = 9) + 

geom_polygon(aes(fill=value), color="white")  + 

scale_fill_brewer(name="Top Index", palette="YlOrRd")
like image 639
aselvendran Avatar asked Aug 14 '16 02:08

aselvendran


1 Answers

To use this option and have it properly update all states we can work with it as an R6 object as follows:

library(choroplethr) 
library(choroplethrMaps)
library(ggplot2) 
data(df_pop_county)

choro              = CountyChoropleth$new(df_pop_county)
choro$title        = "2012 Population Estimates"
choro$ggplot_scale = scale_fill_brewer(name="Population", palette=2, drop=FALSE)
choro$render()

enter image description here

Using the particular pallet you mentioned:

choro              = CountyChoropleth$new(df_pop_county)
choro$title        = "2012 Population Estimates"
choro$ggplot_scale = scale_fill_brewer(name="Population", palette="YlOrRd", drop=FALSE)
choro$render()

enter image description here

like image 58
Hack-R Avatar answered Oct 20 '22 04:10

Hack-R