绘制图例以显示/隐藏所有绘图字符 [英] Plotly legend entry to show/hide all plotting characters
本文介绍了绘制图例以显示/隐藏所有绘图字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我正在构建一个散点图,该散点图显示三个不同的组(在此由颜色指定).通过单击图例中的组,我可以分别显示/隐藏每个组.
Suppose I am building a plotly scatterplot that displays three different groups (here specified by colour). I can show/hide each group individually by clicking at the groups in the legend.
library(ggplot2)
library(plotly)
d <- data.frame("a" = sample(1:50, 20, T), "b" = sample(1:50, 20, T),
"col" = factor(sample(1:3, 20, T)))
gg <- ggplot() + geom_point(aes(x = a, y = b, color = col), data = d)
gg
plotly_build(gg)
是否可以在图例中添加按钮以显示/隐藏所有点?
Is there a way to add a button to the legend to show/hide all points ?
推荐答案
我不知道一种同时切换所有点的方法,但是(如评论中所述,这将是一个合适的选择),可以首先将它们全部隐藏起来,然后一次显示一个点
I don't know of a way to toggle all points simultaneously, but (as indicated in the comments that this would be a suitable alternative) it is possible to start with them all hidden and make points visible one at a time
plot_ly(data=d, x=a, y=b, type='scatter', mode='markers', color=col, visible='legendonly')
这篇关于绘制图例以显示/隐藏所有绘图字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文