如何在 R 中禁用绘图图表的缩放? [英] How to disable the zoom of a plotly chart in R?

查看:14
本文介绍了如何在 R 中禁用绘图图表的缩放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

参见 xaxisyaxis 用于缩放的文档.

See xaxis and yaxis documentation for zooming.

这篇关于如何在 R 中禁用绘图图表的缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆