2016-10-04 92 views
-1

當使用R中的plotly軟件包創建分塊圖時,有什麼方法可以指定分塊大小嗎?在R中繪製 - 指定分塊圖的分塊大小

實施例:

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)

+0

您正在使用什麼版本plotly ?最新的4.x似乎只支持z的連續變量,並帶有連續的彩條圖例。如果您的版本支持分類z值,那麼您可以嘗試'df $ grp = cut(df $ total.exports,c(0,5000,10000,15000 ...)'來生成您的類別,然後使用grp列顏色的choropleth – dww

+0

謝謝!這有幫助。我幾個月前安裝了包,但它似乎最新版本(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)美國國家農業出口「))%>% layout(geo = list(scope =」usa「))我也嘗試過使用df $ grp的分類z值方法,但它似乎生成了一張灰色地圖。 zmin/zmax方法也適用,所以我很好 – spaghettio05

回答

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