我正在尝试将美国的Choropleth地图格式化为特定的颜色,不幸的是,当使用scale_fill_brewer
来改变颜色时;只有48个州(夏威夷和阿拉斯加州没有)。是否有可能知道我是否可以为夏威夷和阿拉斯加实施着色?
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")
答案 0 :(得分:6)
要使用此选项并正确更新所有状态,我们可以work with it as an R6 object,如下所示:
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()
使用您提到的特定托盘:
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()