R 当与geom_箱线图一起传递时,geom_点_交互问题

R 当与geom_箱线图一起传递时,geom_点_交互问题,r,ggiraph,R,Ggiraph,我想知道你是否能帮助我 我经常使用出色的ggiraph,但最近遇到了一个问题,即当一个交互式几何图形与另一个几何图形(来自ggiraph或ggplot2)配对时,它似乎不起作用。让我用下面的例子来解释,并从数据开始 library(ggiraph) library(tidyverse) dput(data) structure(list(moniker = c("OU", "IN", "AI", "HR", "T ", "LA", "AJ", "WC", "BE", "NV"), month

我想知道你是否能帮助我

我经常使用出色的
ggiraph
,但最近遇到了一个问题,即当一个交互式几何图形与另一个几何图形(来自
ggiraph
ggplot2
)配对时,它似乎不起作用。让我用下面的例子来解释,并从数据开始

library(ggiraph)
library(tidyverse)
dput(data)

structure(list(moniker = c("OU", "IN", "AI", "HR", "T ", "LA", 
"AJ", "WC", "BE", "NV"), monthly = c(-0.03489, -0.028034, -0.0374, 
-0.0479, -0.032485, -0.0332, -0.045954, -0.048032, -0.0446, -0.027724
), quarterly = c(-0.096452525515629, -0.0642786819909756, -0.12256466734, 
-0.112914230016, -0.121439751549064, -0.12779609, -0.103490246054841, 
-0.152770470354658, -0.12167068725, -0.0993823354535133), yearly = c(-0.107231010977261, 
-0.00722368758143395, -0.088470240158463, -0.0817767947388421, 
-0.136265993838053, -0.0970216743424386, -0.092159717986092, 
-0.174532024103611, -0.131514750319878, -0.0866996056676958)), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -10L))
换句话说,数据如下所示:

glimpse(data)

Observations: 10
Variables: 4
$ moniker   <chr> "OU", "IN", "AI", "HR", "T ", "LA", "AJ", "WC", "BE", "NV"
$ monthly   <dbl> -0.034890, -0.028034, -0.037400, -0.047900, -0.032485, -0...
$ quarterly <dbl> -0.09645253, -0.06427868, -0.12256467, -0.11291423, -0.12...
$ yearly    <dbl> -0.107231011, -0.007223688, -0.088470240, -0.081776795, -...
。。。生成:

但是,当我尝试使用
geom\u point\u interactive
而不是
geom\u point
时:

data %>% 
  gather(key = "timeframe", value = "return", -moniker) %>% 
  mutate(timeframe = as_factor(timeframe)) %>% 
  ggplot(
    aes(
      x = timeframe, 
      y = return,
      tooltip = moniker
      )
    ) + 
  geom_hline(yintercept = 0) + 
  geom_point_interactive(position = position_jitter(w = 0.15, h = 0)) + 
  geom_boxplot()
。。。我得到以下信息:

(请注意,我无法在此处上载
svg
文件,但可以确认
geom\u point\u interactive
中的工具提示工作正常。)此外,如果我将
geom\u boxplot
替换为
geom\u boxplot\u interactive
,同样的行为似乎也会发生

所以。。。要回答我的问题:您知道一种方法可以保留点上的工具提示,同时具有与上面第一张图片类似的箱线图吗?


一如既往,非常感谢您的关注。

问题在于
geom\u箱线图
继承了
tooltip=moniker
,这意味着每个
moniker
都会有自己的框,为了避免将
tooltip
美学移动到
geom\u point\u interactive
,如下所示:

my_data %>% 
  gather(key = "timeframe", value = "return", -moniker) %>% 
  mutate(timeframe = as_factor(timeframe)) %>% 
  ggplot(
    aes(
      x = timeframe, 
      y = return
    )
  ) + 
  geom_hline(yintercept = 0) + 
  geom_boxplot() + 
  geom_point_interactive(aes(tooltip = moniker), 
                         position = position_jitter(w = 0.15, h = 0))
my_data %>% 
  gather(key = "timeframe", value = "return", -moniker) %>% 
  mutate(timeframe = as_factor(timeframe)) %>% 
  ggplot(
    aes(
      x = timeframe, 
      y = return
    )
  ) + 
  geom_hline(yintercept = 0) + 
  geom_boxplot() + 
  geom_point_interactive(aes(tooltip = moniker), 
                         position = position_jitter(w = 0.15, h = 0))