Skip to content

一些 R 包问题 #11

@XiangyunHuang

Description

@XiangyunHuang

书籍用到了很多 R 包,一些 R 包处于活跃开发和变动中,现将问题记录于此,以便跟进。如下都是一些对书籍影响比较大的 R 包,而且这些 R 包本身影响力也比较大,比如 ggplot2、 spatstat、 gt、 echarts4r 等

ggplot2

问题解决后就勾掉

由于 ggplot2 3.4.0 的改动导致本书使用的一些下游 R 包报出警告,预计 2022 年10月底之前发布 3.4.0 版本。

书中用到以下 R 包的开发版,待新的稳定版本发布后,可以更新 DESCRIPTION 文件

  • davidsjoberg/ggbump 凹凸图 https://github.com/davidsjoberg/ggbump
  • giocomai/ganttrify 甘特图 https://github.com/giocomai/ganttrify
  • ricardo-bion/ggradar 雷达图 https://github.com/ricardo-bion/ggradar
  • ggsurvfit 与 ggplot2 3.5.0 有不兼容的地方 生存分析图 https://github.com/pharmaverse/ggsurvfit
    ggsurvfit(aml_ggsurvfit, linewidth = 1) +
      add_confidence_interval() +
      add_risktable()
    Warning messages:
    1: In ggplot2::geom_blank() :
      All aesthetics have length 1, but the data has 22 rows.
    ℹ Did you mean to use `annotate()`?
    2: In ggplot2::geom_blank() :
      All aesthetics have length 1, but the data has 22 rows.
    ℹ Did you mean to use `annotate()`?
    3: In ggplot2::geom_blank() :
      All aesthetics have length 1, but the data has 22 rows.
    ℹ Did you mean to use `annotate()`?
    4: In ggplot2::geom_blank() :
      All aesthetics have length 1, but the data has 22 rows.
    ℹ Did you mean to use `annotate()`?
    5: In ggplot2::geom_blank() :
      All aesthetics have length 1, but the data has 22 rows.
    ℹ Did you mean to use `annotate()`?
    

spatstat

DT

gt

简单的表格可以一律用 knitr::kable 来做,复杂的表格可以一律用 gt 包做,主要考虑到 gt 的活跃开发现状, gt 和 Quarto 的紧密结合,以及 gt 的扩展生态(比如 gtExtra / gtreg),以及 gt 和 Quarto 都属于 RStudio 大厂持续维护和高投入。

gt gtsummary gtreg gtExtras 等包的文档见 https://github.com/jthomasmock
模型输出考虑 gtsummary 或者 modelsummary

Word 输出中,交叉引用功能失效,需要 Quarto 和相关表格包互相支持,预计 Quarto 1.4 会支持。

  • gt 使用 reactable 将静态表格转为交互表格,因此,后续介绍交互表格将基于 reactable 包
  • gt 的 cols_width() 目前不支持 LaTeX 输出,对于复杂表格有点麻烦 Column widths not porting to LaTeX rstudio/gt#634
  • 用 gt 包制作复杂表格,展示 anscombe 数据(列分组的),展示 UCBAdmissions 数据(列分层分组
  • flextable 在 docx 格式输出中丢失交叉引用,且使用方式和其它包不太一样,配合管道操作还不错。
  • kableExtra 若设置样式,则可能影响其它位置的表格。面对 HTML 和 PDF 输出 kableExtra 需要两套代码。在 PDF 输出中丢失交叉引用,不支持 DOCX 输出。不经常维护,不推荐使用。
  • DOCX 格式输出,两个表格丢失引用,应该是 gt 包的问题 详见 tab_spanner() does not work as intended when output format is docx rstudio/gt#994
WARNING: Unable to resolve crossref @tbl-anscombe-datasets
WARNING: Unable to resolve crossref @tbl-ucb-admissions

已报告,详见 rstudio/gt#1140

  • gt 包使用 tab_spanner 实现列分组,但是列分组在 Word 中不支持,表格整个是乱掉的。但是在 HTML / PDF / EPUB 中是好的。

截屏2022-11-20 07 44 06

emo

echarts4r

Metadata

Metadata

Assignees

No one assigned

    Labels

    docxDOCX 格式相关epubEPUB 格式相关ggplot2ggplot2 包相关gtgt 包相关

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions