问题
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