在R中绘图 - 指定等值区域图的区域大小

时间:2016-10-04 15:32:02

标签: r plotly choropleth

使用R中的plotly包创建一个等值区域图时,有没有办法指定bin大小?

示例:

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

目前,上面的代码自动分为2k步。如果我想说5k步并且最大值为30k,我该怎么做?我希望会有这样的东西(就像直方图一样):

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

1 个答案:

答案 0 :(得分:0)

正如@dww所建议的那样,使用版本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"))