本文介绍了在R中绘图-为Choropleth贴图指定bin大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用R中的plotly包创建Choropleth贴图时,有什么方法可以指定bin的大小吗?
When creating a choropleth map using the plotly package in R, is there any way to specify the bin size?
示例:
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的最大值,我该怎么做?我希望会有这样的东西(就像直方图一样):
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)
bins = list(start = 0, end = 30000, size = 5000)
推荐答案
如@dww所建议,使用版本4.x:
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"))
这篇关于在R中绘图-为Choropleth贴图指定bin大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!