You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ggplotly转换bupaR的trace_explorer绘图显示异常求助

问题:bupaR trace_explorer绘图转ggplotly后样式异常

我尝试用ggplotly将bupaR包中trace_explorer函数生成的静态ggplot转为交互式绘图,但转换后的结果不符合预期——图例丢失,布局和样式严重走样。

复现代码

library(ggplot2)
library(bupaR)

patients <- eventdataR::patients # 来自bupaR的数据集

df <- eventlog(patients,
               case_id = "patient",
               activity_id = "handling",
               activity_instance_id = "handling_id",
               lifecycle_id = "registration_type",
               timestamp = "time",
               resource_id = "employee")

tr <- df %>% processmapR::trace_explorer(type = "frequent", coverage = 1.0)

# tr # 打印原ggplot可查看预期输出
ggplotly(tr)

当前转换后的输出

转换后的交互式图无图例,轨迹的分组样式丢失,布局混乱,与原ggplot的视觉效果差异极大。

已尝试的调整代码

我试过用ggplot2的theme和plotly的layout调整,但仍无法恢复图例,样式依然不符合预期:

ggtrace <- trace_explorer(df,
                          type = "frequent", 
                          coverage = 1.0)

ggtrace <- ggtrace + 
  theme (legend.position="none") +
  theme(axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks.y=element_blank()
  )

plotly_trace <- ggplotly(ggtrace)

layout(plotly_trace, 
       margin=list(l=50, b=50), 
       legend=list(x=1.05)
)

调整后的输出

调整后仍然没有图例,布局和轨迹样式未恢复到原ggplot的状态。

预期效果

希望转换后的交互式绘图完全保留原ggplot的样式(包含清晰的图例、轨迹分组展示),同时具备plotly的交互功能(如悬停显示详情、视图缩放调整等)。

使用的包版本(需保留)

> packageVersion('ggplot2')
[1] ‘3.3.0’
> packageVersion('bupaR')
[1] ‘0.5.2’

内容的提问来源于stack exchange,提问作者AndCh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 18:55:18