I want to have two r plotly choropleth plots in one subplot horizontally (side by side), but nrow=1 does not work, instead they appear vertically (above each other):
library(plotly)
df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv")
g <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
showlakes = TRUE,
lakecolor = toRGB('white')
)
p1 <- plot_ly(z = df$beef, text = df$hover, locations = df$code, type = 'choropleth', locationmode = 'USA-states', color = df$beef, colors = 'Purples',
colorbar = list(title = "Millions USD")) %>% layout(geo = g)
p2 <- plot_ly(z = df$pork, text = df$hover, locations = df$code, type = 'choropleth', locationmode = 'USA-states', color = df$pork, colors = 'Purples',
colorbar = list(title = "Millions USD"), geo = 'geo2') %>% layout(geo2 = g)
plotly::subplot(p1, p2, nrows = 1)
How can I fix (have them above each other than side by side)? And how can I have one common legend/colorbar?

Simply use "domain" to let nrows work.
This renders:
Still have not found a way to share a colorbar for the subplots, so I hide them by 'showscale = F' and use different colors instead.