使用 plotly::rangeslider 时在 y 轴上缩放

Zoom on y-axis while using plotly::rangeslider

我想在使用 rangeslider.

的绘图上放大 y 轴

一个可重现的例子:

library(ggplot2)
library(plotly)
p <- ggplot(faithful, aes(x = waiting)) +
    geom_histogram(bins = 30)
p <- ggplotly(p)
p <- rangeslider(p)
p

我可以缩放的方式如下:

但是,我希望也能像这样缩放(通过不添加 rangeslider 来完成):

我想这可以通过使用类似

的方法来完成
p <- layout(p, dragmode = "zoom")

但我没能完成这项工作。

参考这个GitHub issue,可以通过将fixedrange设置为FALSE for yaxis来完成。

library(ggplot2)
library(plotly)

ggplot(faithful, aes(x = waiting)) +
  geom_histogram(bins = 30) -> p

ggplotly(p) %>% 
  layout(xaxis = list(rangeslider = list()),
         yaxis = list(fixedrange = FALSE)) -> p