禁用特定绘图层(geom)的悬停信息 [英] Disable hover information for a specific layer (geom) of plotly

查看:111
本文介绍了禁用特定绘图层(geom)的悬停信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

library(ggplot2)
library(plotly)

gg <- ggplot(mtcars, aes(factor(vs), drat)) +
    geom_violin() +
    geom_jitter()
ggplotly(gg)

在示例代码中,我们使用ggplot绘制小提琴和抖动层. Plotly显示两层的信息(即,将鼠标悬停在抖动点上时将显示特定的点信息,将鼠标悬停在小提琴图上时也会发生相同的情况).但是,我希望plotly仅显示geom_jitter的信息.

In example code we use ggplot to plot violin and jitter layers. Plotly displays information for both layers (i.e. when hovered over jitter point it will display specific point information, same thing happens when hovered over the violin plot). However, I want plotly to display information only for geom_jitter.

问题:如何为特定图层禁用悬停的信息?

Question: How to disable hovered information for specific layer?

推荐答案

您可以将geomhoverinfo设置为"none":

gg <- ggplot(mtcars, aes(factor(vs), drat)) +
             geom_violin() +
             geom_jitter()
ggply <- ggplotly(gg)

ggply$x$data[[1]]$hoverinfo <- "none"

ggply

这篇关于禁用特定绘图层(geom)的悬停信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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