Reputation: 85
I have been looking for solutions about how to combine in R ggpubr
with plotly
and with crosstalk
to render interactive plots (eg in non-shiny R- markdown).
Upvotes: 0
Views: 52
Reputation: 85
I am glad to find a solution, and to share it with anyone interested...
It is quite simple and merely involves fortify()
.
Here is an example with boxplots - allowing also for filter_select
library(ggpubr)
library(plotly)
library(crosstalk)
# add another numeric col
df=ToothGrowth %>% mutate(len2=len+rnorm(10))
g <- highlight_key(df ,~dose)
p1= g %>% fortify() %>% ggboxplot( x = "dose", y = "len",
color = "dose", palette =c("#00AFBB", "#E7B800", "#FC4E07"),
add = "jitter", shape = "dose")
p2= g %>% fortify() %>% ggboxplot( x = "dose", y = "len2",
color = "dose", palette =c("#00AFBB", "#E7B800", "#FC4E07"),
add = "jitter", shape = "dose")
xx=highlight(subplot(ggplotly(p1),ggplotly(p2)), "plotly_click",selectize = F)
bscols(
filter_select("id", "Select a dose", g, ~dose),
xx,
widths = c(12)
)
Upvotes: 0