Black Lives Matter. Please consider donating to Black Girls Code today.

Axis location in subplots

# install.packages("plotly")
library(plotly)
p1 <- plot_ly(mtcars, x=~mpg, y=~cyl)
p2 <- plot_ly(mtcars, x=~hp, y=~cyl)
s <- subplot(p1, p2, shareY = TRUE) %>% layout(yaxis = list(side = "right"))

As you can see (https://jsfiddle.net/hysa8tLw/), this plot has a y-axis on the right side of the left plot, rather than on the right side of the right plot, which would be preferred behaviour in most cases. Any ideas on how to handle this behaviour?

If I look at the layout field for this axis, I can’t see any option that might specify which plot it is aligned to:
> s$x$layout$yaxis
$domain
[1] 0 1
$showTickLabels
[1] FALSE
$title
[1] “cyl”
$anchor
[1] “x”

Relates to the following issues:
https://github.com/ropensci/plotly/issues/808
https://github.com/Alanocallaghan/heatmaply/issues/5

SOLVED (immediately found the answer in the plotly.js API examples:

s <- subplot(p1, p2, shareY = TRUE) %>% layout(yaxis = list(side = "right", anchor = "x2"))