I am using plotly and have two figures combined with subplot where I mentioned shareX = FALSE
as the ranges for x axis would be different. The data.frame
and 'plot_ly` code is given below:
library(dplyr)
library(plotly)
set.seed(600)
df1 <- data.frame(
class = c(rep("1st", times = 60), rep("2nd", time = 30)),
week = c(rep(1:20, times = 3), rep(1:10, times = 3)),
cat = c(rep("A", times = 20), rep("B", times = 20), rep("C", times = 20), rep("A", times = 10), rep("B", times = 10), rep("C", times = 10)),
count = round(runif(90, 1, 100))
)
df1 %>%
split(df1$class) %>%
purrr::map(~{
plotly::plot_ly(.x, x = .x$week, y = .x$count, type = "bar", split = .x$cat) %>%
layout(
barmode = "group",
showlegend = FALSE,
updatemenus = list(list(
active = -1,
type = 'buttons',
buttons = list(
list(label = "1st 2W",
method = "relayout",
args = list("xaxis.range", c(0.5, min(.x$week)+1.5)))
)
))
)
}) %>%
plotly::subplot(nrows = 2,
shareY = FALSE,
shareX = FALSE,
margin = 0.05
)
In this case the button is updating the first plot only where as if I mention shareX = TRUE
then it would update both the plots. Is it possible to use updatemenus while shareX = FALSE
?