r - 我可以使用 Plotly 的自定义更新菜单按钮来更新 x 轴范围,而 shareX = FALSE 在子图中?
问题描述
我正在使用 plotly 并将两个数字与 subplot 结合在一起,我提到shareX = FALSE
x 轴的范围会有所不同。和“plot_ly ”data.frame
代码如下:
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
)
在这种情况下,按钮只会更新第一个图,就像我提到的shareX = TRUE
那样,它会更新两个图。是否可以使用 updatemenus while shareX = FALSE
?
解决方案
推荐阅读
- python - 如何在 python 中使用训练有素的 Tensorflow Lite 模型?
- python - 我可以使用另一个类内部的函数中的变量吗?
- javascript - 在 JavaScript 中使用 Selenium 处理“接受 Cookie”弹出窗口
- react-native - 发送正文 React Native - PHP
- javascript - TypeError:无法读取未定义 discord.js 的属性“解决”
- windows - 从 Bat 文件中的 .tar 文件中获取特定文件
- php - 尝试了我在堆栈上找到的所有内容,但没有任何东西可以修改我的数组 php
- cryptography - 使用STM32加密库生成签名
- json - 如何动态获取json值?
- amazon-web-services - DynamoDbException:条件的长度只能是 1 或 2