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

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

问题描述

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

解决方案

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

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

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

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

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

图书馆(情节)plot_ly(x = 1:10,y = 1:10) %>%布局(xaxis = list(fixedrange = TRUE),yaxis = list(fixedrange = TRUE))

参见 xaxisyaxis 缩放文档.

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.

解决方案

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.

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

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