我想知道您是否能帮助我。
我经常使用出色的ggiraph
,但是最近遇到了一个问题,当它的一个交互式几何图形与另一个几何图形(来自ggiraph
或{{ 1}})。让我在下面的示例中进行解释,并从数据开始。
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, -...
...生成:
但是,当我尝试使用data %>%
gather(key = "timeframe", value = "return", -moniker) %>%
mutate(timeframe = as_factor(timeframe)) %>%
ggplot(
aes(
x = timeframe,
y = return
)
) +
geom_hline(yintercept = 0) +
geom_point(position = position_jitter(w = 0.15, h = 0)) +
geom_boxplot()
而不是geom_point_interactive
时:
geom_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_point_interactive
,似乎也会发生相同的行为。与geom_boxplot
。
所以...让我问一个问题:您是否知道一种在上面保留点样图的方法,同时具有类似于上图所示的箱形图? < / p>
一如既往,非常感谢您的关注。
答案 0 :(得分:2)
问题在于geom_boxplot
继承了tooltip = moniker
,这意味着每个moniker
都将拥有自己的盒子,以避免将tooltip
的美感移至{{1} }:
geom_point_interactive