Disable hover information for a specific layer (geom) of plotly

落花浮王杯 提交于 2019-12-08 01:18:16

问题


library(ggplot2)
library(plotly)

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

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?


回答1:


You can set the hoverinfo to "none" for that geom:

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

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

ggply



来源:https://stackoverflow.com/questions/45801389/disable-hover-information-for-a-specific-layer-geom-of-plotly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!