I'm trying to use ggiraph to link 2 interactive graphs together as Sharon has shown here : https://www.infoworld.com/article/3626911/easy-interactive-ggplot-graphs-in-r-with-ggiraph.html
I managed to plot both graphs side by side. When I hover the mouse over a bar, it pops up with extra info and the bar 'lights up' but only "individually"
Problem: I cannot get them linked. Ideally I would like the related bars in both plots to light up simultaneously, as shown in video here at minute 6.25 https://www.youtube.com/watch?v=12QaZp1FokU&t=421s
This is my data
library(tidyverse)
library(here)
library(janitor)
library(skimr)
library(RColorBrewer)
library(ggiraph)
library(patchwork)
library(Rcpp)
structure(list(statistical_area = c("Baulkham Hills and Hawkesbury",
"Baulkham Hills and Hawkesbury", "Blacktown", "Blacktown", "Central Coast",
"Central Coast", "City and Inner South", "City and Inner South",
"Eastern Suburbs", "Eastern Suburbs", "Inner South West", "Inner South West",
"Inner West", "Inner West", "North Sydney and Hornsby", "North Sydney and Hornsby",
"Northern Beaches", "Northern Beaches", "Outer South West", "Outer South West",
"Outer West and Blue Mountains", "Outer West and Blue Mountains",
"Parramatta", "Parramatta", "Ryde", "Ryde", "South West", "South West",
"Sutherland", "Sutherland"), year = c("x2019", "x2020", "x2019",
"x2020", "x2019", "x2020", "x2019", "x2020", "x2019", "x2020",
"x2019", "x2020", "x2019", "x2020", "x2019", "x2020", "x2019",
"x2020", "x2019", "x2020", "x2019", "x2020", "x2019", "x2020",
"x2019", "x2020", "x2019", "x2020", "x2019", "x2020"), cases = c(7329,
8758, 45657, 47669, 30877, 30840, 65274, 67286, 18695, 19416,
41880, 42581, 15860, 16223, 19178, 18800, 12198, 11483, 28751,
27775, 33910, 35107, 41824, 41538, 7611, 7674, 41396, 45330,
15997, 17418), crime_per_day = c(20.08, 23.99, 125.09, 130.6,
84.59, 84.49, 178.83, 184.35, 51.22, 53.19, 114.74, 116.66, 43.45,
44.45, 52.54, 51.51, 33.42, 31.46, 78.77, 76.1, 92.9, 96.18,
114.59, 113.8, 20.85, 21.02, 113.41, 124.19, 43.83, 47.72)), row.names = c(NA,
-30L), class = c("tbl_df", "tbl", "data.frame"))
and the plot section:
plot_2019<-crimeperday %>%
filter(year=="x2019") %>%
ggplot(aes(x=reorder(statistical_area,crime_per_day),y=crime_per_day))+
geom_col_interactive(aes(tooltip=crime_per_day,data_id=crime_per_day))+
coord_flip()
plot_2020<-crimeperday %>%
filter(year=="x2020") %>%
ggplot(aes(x=reorder(statistical_area,crime_per_day),y=crime_per_day))+
geom_col_interactive(aes(tooltip=crime_per_day,data_id=crime_per_day))+
coord_flip()
girafe(code=print(plot_2019+plot_2020))
Could you please help? thank you so much!