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

R语言Plotly旭日图如何移除标签并导出为TIF/PDF静态文件

R plotly 旭日图问题解决方案

移除旭日图扇区显示的标签

在plot_ly()的sunburst配置中加入textinfo = "none"参数即可完全隐藏扇区上的固定标签,该设置不会影响鼠标悬停时的提示弹窗内容。
修改后的可运行代码:

fig <- plotly::plot_ly(
  labels = c("total", "Discharged", "Admitted", "Transferred", "Direct", "Indirect"),
  parents = c("", "total", "total", "total", "Transferred", "Transferred"),
  values = c(5538, 1044, 4031, 297, 220, 76), 
  type = "sunburst",
  branchvalues = "total",
  textinfo = "none"
)
fig

导出静态TIF/PDF格式文件

推荐使用kaleido引擎做静态导出,支持直接输出矢量PDF和高分辨率TIF,适配出版需求,操作流程:

  • 首次使用前安装配置依赖:
    install.packages(c("plotly", "reticulate"))
    # 未安装过Python miniconda环境时运行下一行,已安装可跳过
    reticulate::install_miniconda()
    # 自动安装kaleido导出依赖,按提示确认即可
    plotly::kaleido()
    
  • 绘图完成后执行导出命令:
    # 导出矢量PDF
    plotly::export(fig, file = "sunburst_output.pdf")
    # 导出300DPI的TIF格式,可自行调整宽高参数
    plotly::export(fig, file = "sunburst_output.tif", width = 2400, height = 2400, res = 300)
    
  • 若kaleido配置失败,可使用备选方案:先用htmlwidgets::saveWidget(fig, "temp_sunburst.html", selfcontained = T)保存为本地HTML文件,再调用webshot2::webshot(url = "temp_sunburst.html", file = "sunburst_output.pdf")完成导出,导出TIF时只需修改文件后缀、添加dpi参数即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.27 12:18:13