Skip to content

ggplotly + subplot(shareX=TRUE) causes date axis tick labels to disappear after zoom/pan #2489

@furuks17

Description

@furuks17

Description

When combining two ggplotly() objects using subplot(..., shareX = TRUE), x-axis tick labels disappear after zooming/panning.

This happens specifically with date-time x axes.

The hover labels still show correct datetime values, but axis ticks disappear.

Reproducible example

library(tidyverse)
library(lubridate)
library(plotly)
library(viridisLite)

d = tibble(
  time = seq(
    ymd_hms("2019-01-01 00:00:00"),
    by = "10 sec",
    length = 1e5
  ),
  y = cumsum(rnorm(1e5))
)

d2 = expand.grid(
  date = unique(date(d$time)),
  y = 48 / 2^8 * 2^(seq(
    0,
    log2(48 / (48 / 2^8)),
    by = 1/20
  ))
) %>%
  as_tibble() %>%
  mutate(z = rnorm(n()))

g1 = ggplot(d, aes(time, y)) +
  geom_line(linewidth = 0.3) +
  theme_bw()

g2 = ggplot(
  d2 %>%
    mutate(date = as.POSIXct(date) + 12*3600),
  aes(date, log2(y), fill = z)
) +
  geom_raster() +
  scale_fill_gradientn(colours = turbo(100)) +
  theme_bw()

p1 = ggplotly(g1)
p2 = ggplotly(g2)

subplot(
  p1,
  p2,
  nrows = 2,
  shareX = TRUE
) %>%
  layout(
    dragmode = "pan"
  )

Expected behavior

x-axis tick labels should remain visible and automatically update during zoom/pan.

Actual behavior

x-axis tick labels disappear after zooming/panning.

Session info

sessionInfo()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions