简体   繁体   中英

Counties within One State Choropleth Map

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM