如何在情节中自定义或显示模式栏?自定义、情节、模式、如何在

2023-09-06 07:05:30 作者:格调 Moment゜

我想自定义模式栏(在右上角),以便只保留缩放"、平移"、框选"、放大"和缩小".如果不可能,我更喜欢显示模式栏.

I would like to custom the modebar (on top right) so as to keep just "zoom","pan","box select","zoom in" and "zoom out". If it's not possible, I prefer display the modebar.

这里的图表和代码:

x <- c(1:15)
y <- c(1:15)
xy <- as.data.frame(cbind(x,y))
example <- ggplot(data = xy,aes(x = x,y = y))+geom_line()
ggplotly(example)

感谢您的帮助

推荐答案

用你的例子:

x <- c(1:15)
y <- c(1:15)
xy <- as.data.frame(cbind(x,y))
example <- ggplot(data = xy,aes(x = x,y = y))+geom_line()

ggplotly(example) %>% config(displaylogo = FALSE,
modeBarButtonsToRemove = list(
    'sendDataToCloud',
    'toImage',
    'autoScale2d',
    'resetScale2d',
    'hoverClosestCartesian',
    'hoverCompareCartesian'
))

示例输出

其他选项包括:'zoom2d'、'pan2d'、'select2d'、'lasso2d'、'zoomIn2d' 和 'zoomOut2d'

Other options include: 'zoom2d','pan2d','select2d','lasso2d','zoomIn2d', and 'zoomOut2d'