NiklasvMoers
NiklasvMoers

Reputation: 329

Zoom on y-axis while using plotly::rangeslider

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.

Upvotes: 8

Views: 5802

Answers (1)

M--
M--

Reputation: 28826

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

Upvotes: 9

Related Questions