Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 717
pogibas Avatar asked Aug 21 '17 15:08

pogibas


1 Answers

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

enter image description here

like image 131
M-- Avatar answered Nov 20 '22 00:11

M--