0
我正在使用提供的示例並將其擴展爲如下生成兩個choropleth子圖。我只得到一個情節和奇怪的更高的規模:plotly r choropleth with subplot not working as working desired
library(plotly)
df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv")
df$hover <- with(df, paste(state, '<br>', "Beef", beef, "Dairy", dairy, "<br>", "Fruits", total.fruits, "Veggies", total.veggies,
"<br>", "Wheat", wheat, "Corn", corn))
# give state boundaries a white border
l <- list(color = toRGB("white"), width = 2)
# specify some map projection/options
g <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
showlakes = TRUE,
lakecolor = toRGB('white')
)
p1 <- plot_ly(df, z = total.exports, text = hover, locations = code, type = 'choropleth', locationmode = 'USA-states', color = total.exports, colors = 'Purples',
marker = list(line = l), colorbar = list(title = "Millions USD"))
p2 <- plot_ly(df, z = total.exports, text = hover, locations = code, type = 'choropleth', locationmode = 'USA-states', color = total.exports, colors = 'Purples',
marker = list(line = l), colorbar = list(title = "Millions USD"))
plotly::subplot(p1, p2, nrows = 2) %>% layout(geo = g)
我誤解或失蹤?
謝謝。有可能有不同的比例嗎?我有這樣的數據。 – Gopala
您應該將此信息添加到您的原始帖子中。我看了看,似乎有可能有多個傳說(通過legendgroup)其他類型的情節,但我不知道是否有可能的choropleth地圖。我嘗試了一些東西,但它沒有奏效:-)很明顯你想要什麼樣的最終輸出,但是你可以使用Rmarkdown(html doc),並且有兩張地圖,每張都有自己的圖例 – MLavoie
對不起...另外,它沒有在我的電腦上產生所需的結果。我正在使用'packageVersion('plotly')[1]'3.4.1'' – Gopala