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

时间:2017-02-12 23:25:12

标签: r legend choropleth choroplethr

我试图在R中绘制美国地图,其中包含州级信息指标(例如人口)。我希望根据要绘制的度量以颜色标度显示状态。我真的很喜欢state_choropleth()包中的choroplethr函数。但是,我想自定义状态bin大小。例如,当我使用以下代码时:

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

我得到了等值线图,图例显示了7个箱子。第一个仓的范围为[562,803至1,052,471],最后一个仓的范围为[11,533,561至37,325,068]。如果我想设置格式[0到1,000,000]的bin大小,该怎么办? [1,000,000至5,000,000]; ... 等等?我查了但是我知道state_choropleth()函数没有可以用来设置bin大小的参数。

我发现了这个相关的问题:plotly in R - specifying bin size for choropleth maps,我尝试使用https://plot.ly/r/choropleth-maps/#choropleth-maps-in-r中给出的plot_ly()示例。但是,我只能看到传说而不是我的RStudio中的地图,如截屏截面的右下角所示:Screenshot of plotly in RStudio

任何帮助/建议表示赞赏。谢谢!

1 个答案:

答案 0 :(得分:0)

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

确保将num_colors设置为1。