ggplotly can't change axis range with dynamic ticks
Hi, I tried to make a plot with a zoom and with dynamic ticks. But after the rendering there is no zoom.
library(plotly)
df = data.frame(x=rnorm(100), y=rnorm(100))
g <- ggplot(df, aes(x=x, y=y)) + geom_point()
ggplotly(g, dynamicTicks = TRUE) %>% layout(xaxis = list(range = c(-0.5,0.5)))
Maybe this is incompatible or there is an other way to do it? Thanks
That's strange, can you include a screenshot of the modebar?

I faced this problem today as well. I've realized that dynamicTicks argument sets autorange to be true - thus the provided range is ignored. To leverage an explicit range, one has to explicitly disable autorange. This worked for me:
library(plotly)
library(ggplot2)
p <- ggplot(
data = mtcars,
aes(x = wt, y = mpg, color = factor(cyl))
) + geom_point()
ggplotly(p, dynamicTicks = TRUE) |>
layout(
yaxis = list(
range = c(0, 50),
autorange = FALSE
)
)
Thank you @Gotfrid! I was experiencing the same issue with my plots made with ggplotly and your solution works perfectly on all of them.