Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
157 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...