I try to reorder drv
and class
in mpg
data, and then plot the boxplots of hwy
with those two character variables as fill
argument in aes
of the ggplot
. I use giraffe
for that. But when I put the graphs together the hover effect not works properly. I want the plots to be synced in a way that hovering mouse in one of them results in same color effect.
library(tidyverse)
library(ggiraph)
library(patchwork)
g1 <- mpg %>%
mutate(drv = (fct_reorder(drv, hwy))) %>%
ggplot(aes(x = hwy, y = drv, fill = drv, data_id = drv)) +
geom_boxplot_interactive() +
theme(legend.position = 'none')
g2 <- mpg %>%
mutate(class = (fct_reorder(class , hwy))) %>%
ggplot(aes(x = hwy, y = class , fill = drv, data_id = drv)) +
geom_boxplot_interactive() +
theme(legend.position = 'none')
girafe(
ggobj = g1 + plot_spacer() + g2 + plot_layout(widths = c(0.45, 0.1, 0.45)),
options = list(
opts_hover(css = ''),
opts_hover_inv(css = "opacity:0.1;"),
opts_sizing(rescale = FALSE)
),
height_svg = 5,
width_svg = 9
)