带有情节和串扰的交互式ggpubr

问题描述 投票:0回答:1

我一直在寻找有关如何在 R

ggpubr
中与
plotly
crosstalk
组合以渲染交互式绘图的解决方案(例如在非闪亮的 R-markdown 中)。

r plotly ggpubr crosstalk
1个回答
0
投票

我很高兴找到解决方案,并与任何感兴趣的人分享...... 很简单,只涉及

fortify()

这是一个箱线图示例 - 也允许

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)
)
© www.soinside.com 2019 - 2024. All rights reserved.