与 ggiraph 的交互式方面图:不响应鼠标悬停

问题描述 投票:0回答:1

我的目标是在 R 中生成交互式组合线图和面点图。将鼠标移动到其中一条线上应将其与相应的点图面一起突出显示,反之亦然。我一直在尝试遵循 Albert Rapp 的方法 使用 ggiraph 和 patchwork。

但是,目前我一直在生成交互式方面图。以下是生成无响应分面图的代码示例:

library(ggirafe) 
library(ggplot2) 

# Sample data 
data <- 
    data.frame( 
        x = rnorm(100), 
        y = rnorm(100), 
        facet = rep(c("A", "B", "C"), 
        length.out = 100) 
        ) 

# Create the ggplot 
p <- 
    ggplot(
        data, aes(x, y), 
        data_id = facet
        ) + 
    geom_point() +
    facet_wrap_interactive(~facet)

# Create the girafe object with hover options 
girafe(
    ggobj = p, 
    options = 
        list( opts_hover(css = ""), 
        opts_hover_inv(css = "opacity:0.1;") 
        )
    )

感谢您的任何建议!

r ggplot2 mouseover facet ggiraph
1个回答
0
投票

根据我的理解和查看ggiraph书,使刻面条具有交互性需要使用

labeller_interactive
来设置
data_id

library(ggiraph)
library(ggplot2)

set.seed(123)

# Sample data
data <-
  data.frame(
    x = rnorm(100),
    y = rnorm(100),
    facet = rep(c("A", "B", "C"),
      length.out = 100
    )
  )

p <-
  ggplot(
    data, aes(x, y)
  ) +
  geom_point() +
  facet_wrap_interactive(
    ~facet,
    labeller = labeller_interactive(
      aes(
        tooltip = paste("this is facet", facet), 
        data_id = facet
      )
    )
  )

girafe(
  ggobj = p,
  options =
    list(
      opts_hover(""),
      opts_hover_inv(css = "opacity:0.1;")
    )
)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.