I would like to zoom in on the y-axis on a plotly plot that uses rangeslider.
A reproducible example:
library(ggplot2)
library(plotly)
p <- ggplot(faithful, aes(x = waiting)) +
geom_histogram(bins = 30)
p <- ggplotly(p)
p <- rangeslider(p)
p
The way I can zoom is the following:

However, I would like to be able to also zoom like this (which is done by not adding a rangeslider):

I assume this can be done by using something along the lines of
p <- layout(p, dragmode = "zoom")
but I haven't been able to make this work.
In reference to this GitHub issue, it can be done by setting fixedrange to 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

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With