简体   繁体   English

在 R 中的 state_choropleth 函数中自定义 bin 大小?

[英]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).我正在尝试使用州级信息指标(例如人口)在 R 中绘制美国地图。 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.我真的很喜欢choroplethr包中的state_choropleth()函数。 However, I want to customize the state bin size.但是,我想自定义 state bin 大小。 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.我得到了等值线图,图例显示了 7 个箱子。 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].第一个 bin 的范围是 [562,803 到 1,052,471],最后一个 bin 的范围是 [11,533,561 到 37,325,068]。 What if I want to set the bin sizes of the form [0 to 1,000,000];如果我想设置 [0 到 1,000,000] 形式的 bin 大小怎么办? [1,000,000 to 5,000,000]; [1,000,000 至 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.我检查过,但我知道state_choropleth()函数没有可用于设置 bin 大小的参数。

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 .我发现了这个相关问题: plotly in R - specifying bin size for choropleth maps ,我尝试使用plot_ly()中给出的示例: 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但是,我只能在我的 RStudio 中看到图例而不是地图,如屏幕截图右下角所示: RStudio 中 plotly的屏幕截图

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.确保将 num_colors 设置为 1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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