plotly in R - specifying bin size for choropleth maps

。_饼干妹妹 提交于 2019-12-13 07:50:50

问题


When creating a choropleth map using the plotly package in R, is there any way to specify the bin size?

Example:

library(plotly)
df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv")
plot_ly(df, z=total.exports, locations=code, type="choropleth", locationmode="USA-states", colors = 'Purples', filename="", colorbar=list(title = "2011 US Agriculture Exports by State")) %>% 
layout(geo = list(scope="usa"))

Currently, the above code auto-bins into 2k steps. If I wanted say 5k steps and a max value of 30k, how would I do that? I was hoping there would be something like this (as there is with histograms):

bins = list(start = 0, end = 30000, size = 5000)


回答1:


As suggested by @dww, using version 4.x:

plot_ly(df, z=~total.exports, locations=~code, zmin=0, zmax = 30000, type="choropleth", locationmode="USA-states", colors = 'Purples', filename="", colorbar=list(title = "2011 US Agriculture Exports by State")) %>% layout(geo = list(scope="usa"))


来源:https://stackoverflow.com/questions/39856340/plotly-in-r-specifying-bin-size-for-choropleth-maps

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