如何在 R 中禁用绘图图表的缩放?缩放、图表、如何在

2023-09-06 07:47:36 作者:光辉时刻

我没有找到一个参数来禁用绘图图形上鼠标光标的缩放模式.这很糟糕,因为当您在手机上拖动手指时,缩放会增加.利用这个问题,我想从情节中删除所有按钮,只留下下载图像的按钮.

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.

推荐答案

你可以做很多事情!plotly 中的按钮行称为modebar";您可以将其完全删除,或从中删除特定按钮:

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"))

在本书中查看更多详细信息使用 R、plotly 和闪亮的基于 Web 的交互式数据可视化.

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

(不幸的是,文档非常简短.)

(Documentation is unfortunately very brief.)

如果您不仅要禁用按钮,还要完全禁用缩放,请使用带有 xaxisyaxis 参数的 layout()通过 fixedrange 设置修复坐标轴范围(注意它必须是一个列表):

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))

参见 xaxis 和 yaxis 用于缩放的文档.

See xaxis and yaxis documentation for zooming.