rplotlyggplotly

Autorange axes after zoom in ggplotly or plot_ly


Zooming in to a ggplotly far enough makes the axes disappear. How do I autorange them as the plot is zoomed?

library(ggplot2)
library(plotly)
myplot <- ggplot(cars, aes(speed, dist)) +
    geom_point()

ggplotly(myplot)

ggplotly(myplot) %>%
    layout(xaxis = list(autorange = TRUE),
           yaxis = list(autorange = TRUE))

Solution

  • When it was carried over from ggplot it manually set the tick values and tick text, overriding everything else. If you want ticks to be automatic, the tick mode needs to be set to auto.

    ggplotly(myplot) %>% 
      layout(xaxis = list(tickmode = "auto"), yaxis = list(tickmode = "auto"))
    
    

    zoomed view