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

大兔子大兔子 提交于 2019-12-12 10:38:19

问题


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")

回答1:


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()

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()



来源:https://stackoverflow.com/questions/38938565/alaska-and-hawaii-not-formatting-correctly-for-county-choropleth-map-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!