plotly.R icon indicating copy to clipboard operation
plotly.R copied to clipboard

Incorrect behavior of dynamicTicks vs autorange in facet mode

Open NShaforostov opened this issue 7 years ago • 5 comments

Hello! I want to use dynamic ticks for plots in application. With that, need not to limit the plot by x axis (i want some spaces on the borders). I do that by "autorange = FALSE" in layot. For single plot it's work fine, but for facet_wrap or facet_grid plots it works fine only for the first plot (left). I tried to use xlim, coord_cartesian with xlim, scale_x_continuous. Nothing helps. Plots are created using ggplot2 (ver. 3.1.0) and then rendered using ggplotly (plotly ver. 4.8.0).

My code:

library(data.table)
library(plotly)
library(ggplot2)

a1 <- c(1:50)
b1 <- rnorm(50, 30, 10)
c1 <- c(rep(c("abc","def"),25))
dt <- as.data.table(list("valueX" = a1, "valueY" = b1, "facetCol" = c1))
dt$facetCol <- as.factor(dt$facetCol)

pplot <- ggplot() + geom_line(data = dt, aes(x = valueX, y = valueY)) +
                    facet_wrap(~dt$facetCol, ncol = 2)
ggplotly(dynamicTicks = TRUE, pplot) %>% layout(xaxis = list(autorange = FALSE))

How i see it: 1

What i want: 2

NShaforostov avatar Nov 29 '18 14:11 NShaforostov

Yea, dynamicTicks = TRUE should do a better job of preserving the range of the positional scale, but in the meantime, you could set it yourself this way

ggplotly(dynamicTicks = TRUE, pplot) %>% 
  layout(xaxis = list(autorange = FALSE, range = c(-10, 100)))

cpsievert avatar Dec 05 '18 23:12 cpsievert

Thanks for answer! Yeah, i tried to use "range". But it works incorrect too: withrange

NShaforostov avatar Dec 06 '18 09:12 NShaforostov

Same issue here (on y axis though but the issue still holds the same). Couldn't find a fix for this.

homer3018 avatar Apr 07 '21 12:04 homer3018

Apologies for poking this again, but it'd be great to have a way of ensure a specific range to all facets, while this is getting fixed. Is there a way to achieve that ?

homer3018 avatar May 07 '21 08:05 homer3018

I also ran into the problem of not being able to get fixed axis ranges for facetted plots when using dynamicTicks = TRUE (which I need to use for rangeslider and rangeslider to work properly).

Using layout(xaxis = list(autorange = FALSE, range = c(-10, 100))) only affects the first facet not the others. Are there any other solutions? Thanks!

januz avatar Jun 30 '22 23:06 januz