admin管理员组

文章数量:1278653

ggiraph is great! But I'm wondering if there's a way to set default css properties for data_id items outside of opts_hover()/opts_hover_inv(). Here's a minimal reprex:

library(ggplot2)
library(ggiraph)

ggobj <- 
  mtcars |>
  ggplot(aes(x = qsec,
             y = hp,
             color = as.character(gear),
             data_id = gear)) + 
  geom_point_interactive(alpha = 0.5)

girafe(
  ggobj = ggobj,
  options = list(
    opts_hover("opacity:1;"),
    opts_hover_inv("opacity:0;")
  )
)

Here, each point is at 50% opacity when I'm not hovering on anything:

When I hover on one gear type, the others disappear as expected due to the css in opts_hover_inv(). However, the the hovered gear stays at 50% opacity. I think that this is because it's treating opacity and alpha as two separate entities. So when I'm hovering, the hovered group has 1 * 0.5 opacity.

Is there a way to get the desired output of:

  • default to 50% opacity when not hovering
  • hovered elements tied to the data_id go to 100% opacity
  • inverse of hovered elements go to 0% opacity

本文标签: rset default opacity using ggiraphgirafeStack Overflow