Counties within One State Choropleth Map

为君一笑 提交于 2019-12-12 12:57:55

问题


I'm struggling to customize and find the right code to structure the choropleth map that I am attempting to make of profit of a business by county in a specific state.

What I have done so far is be able to plot my code, albeit with a color palette that I don't want and breaks that are undesirable as well.

library(choroplethr)
library(ggplot2)

county <- data.frame(region = c(19001,19013,19017,19019,19021,19023,19033,19035),
                 value=c(-37102,-41052,35016,-13180,-8062,6357,-46946,-5380))

county_choropleth(county, "Test", state_zoom = "iowa") + scale_fill_brewer("Test",palette="Blues")

And I get this plot:

Ideally, I would like to be able to customize the color palette to be blue when positive and red when negative. Also, creating more breaks in the color scale between these 2 colors would be ideal as well. I would like to make the breaks more pleasant numbers such as "35,000", "0", etc. not $35,016, ha. Finally, I would like to make all NA counties, based on FIPS codes, grey or a different color than one that would take place on the scale.

I have unsuccessfully tried to use different variations of the scale_colour_gradient command and its "sibling" commands.

Please, let me know if you need any clarification or more code. Thank you for any and all help!


回答1:


You could try

county_choropleth(county, "Test", state_zoom = "iowa", num_colors = 1) + 
  scale_fill_gradient2(high = "blue", 
                       low = "red", 
                       na.value = "grey90", 
                       breaks = pretty(county$value, n = 10), 
                       label = scales::dollar_format())


来源:https://stackoverflow.com/questions/33112514/counties-within-one-state-choropleth-map

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