pogibas
pogibas

Reputation: 28339

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?

Upvotes: 11

Views: 3058

Answers (1)

M--
M--

Reputation: 28825

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

Upvotes: 17

Related Questions