10
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?

M--
  • 25,431
  • 8
  • 61
  • 93
pogibas
  • 27,303
  • 19
  • 84
  • 117

1 Answers1

15

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

M--
  • 25,431
  • 8
  • 61
  • 93