简体   繁体   中英

Customize bin size in state_choropleth function in R?

I am trying to plot a map of the US in R, with state-level information metric (eg, population). I want the states to be displayed in a color scale according to the metric to be plotted. I really liked the state_choropleth() function in the choroplethr package. However, I want to customize the state bin size. For example, when I use the following code:

library(choroplethr)
library(choroplethrMaps)
?df_pop_state
data(df_pop_state)
head(df_pop_state)
state_choropleth(df_pop_state)

I get the choropleth map and the legend shows 7 bins. The first bin has a range [562,803 to 1,052,471] and the last one has the range [11,533,561 to 37,325,068]. What if I want to set the bin sizes of the form [0 to 1,000,000]; [1,000,000 to 5,000,000]; ... and so on? I checked but I understand that there are no arguments for the state_choropleth() function that can be used to set the bin size.

I found this related question: plotly in R - specifying bin size for choropleth maps , and I tried using the plot_ly() example given in: https://plot.ly/r/choropleth-maps/#choropleth-maps-in-r . However, I am only able to see the legend and not the map in my RStudio as seen in the bottom right corner of the screenshot here: Screenshot of plotly in RStudio

Any help/suggestion is appreciated. Thanks!

state_choropleth(df,
                 title = "title of the graph",
                 num_colors = 1) + 
  scale_fill_continuous(low='white', 'high'='blue',limits=c(0,100000)) + 
  labs(fill = "title of the legend")

Make sure you set num_colors to 1.

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