Is there a way that I can manually control the thresholds between various range on choroplethr?

久未见 提交于 2020-01-03 02:22:13

问题


I would like to be able to manually control the thresholds between population ranges on choroplethr package.

library(choroplethr)

data(df_pop_county)        
data(continental_us_states)

county_choropleth(df_pop_county, 
                  state_zoom = continental_us_states)


回答1:


You can use cut to create the custom breaks:

# rename the original "value" column if you don't want to write over it
names(df_pop_county) <- c("region", "original_value")

# define the breaks you want
df_pop_county$value <- cut(df_pop_county[["original_value"]],
                           breaks = c(0, 1e4, 5e4, 1e5, 5e5, 1e6, 1e7))
# if you want custom labels to go along with those breaks, then provide
# the labels argument in cut:
# cut(df_pop_county[["original_value"]],
#     breaks = c(0, 1e4, 5e4, 1e5, 5e5, 1e6, 1e7),
#     labels =c( "0-9999","10000-49999", "50000-99999", "100000-499999", "500000-999999", "1000000-10000000"))



来源:https://stackoverflow.com/questions/41003313/is-there-a-way-that-i-can-manually-control-the-thresholds-between-various-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!