3

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:

enter image description here

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!

Ari
  • 1,819
  • 14
  • 22
medavis6
  • 843
  • 10
  • 32
  • 3
    Have you tried `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))`? – lukeA Oct 13 '15 at 21:24
  • Now I have and it works like a charm! My only last question being the ability to tweak the legend so it says $600,000 instead of 6e+05. Thanks again! If you respond with your comment as an answer, I'll gladly mark it as the correct one. – medavis6 Oct 13 '15 at 21:59

1 Answers1

6

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())
lukeA
  • 53,097
  • 5
  • 97
  • 100