How to disable the zoom of a plotly chart in R?

吃可爱长大的小学妹 提交于 2021-01-28 19:54:42

问题


I didn't find an argument to disable the zoom mode of the mouse cursor on a plotly graph. This is bad because when you drag your fingers across your phone, the zoom increases. Taking advantage of the question, I would like to remove all the buttons from the plotly and leave only the button to download the image.


回答1:


There is a lot you can do! The button line in plotly is called "modebar" and you can remove it completely, or remove specific buttons from it:

plot_ly() %>%
  config(modeBarButtonsToRemove = c("zoomIn2d", "zoomOut2d"))

See more details in the book Interactive web-based data visualization with R, plotly, and shiny.

(Documentation is unfortunately very brief.)

If you want not only to disable buttons, but also to disable zooming completely, use layout() with xaxis and yaxis arguments to fix the axis range by fixedrange settings (note it has to be a list):

library(plotly)

plot_ly(x = 1:10,y = 1:10) %>%
    layout(xaxis = list(fixedrange = TRUE), yaxis = list(fixedrange = TRUE))

See xaxis and yaxis documentation for zooming.



来源:https://stackoverflow.com/questions/62852809/how-to-disable-the-zoom-of-a-plotly-chart-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!