knitr 在 ggplots 中渲染缺失的标签

knitr render missing labels in ggplots

我正在将 Snakemake 管道所需的软件容器化。其中包括 R 4.0.2 安装以及 Tidyverse 和一些 Bioconductor 包(全部通过 Conda Forge)。大多数情况下似乎一切正常,但是,一步通过 knitr::render 呈现 .Rmd 文档。文档渲染 运行s 没有错误,但是 HTML 中的 ggplot 图像缺少所有标签:

当我在同一台机器上的 Conda 环境中 运行 这段代码时,它工作正常。我怀疑在需要安装在 Docker 容器中的图像中渲染文本需要一些库。 有没有人遇到过这种情况?是否需要将特定库添加到容器中才能解决此问题?

The container image是public,如果有人想用它来测试的话。


附加信息

Session 信息

这是渲染后的 sessionInfo() 输出 HTML。

## R version 4.0.2 (2020-06-22)
## Platform: x86_64-conda_cos6-linux-gnu (64-bit)
## Running under: Debian GNU/Linux 10 (buster)
## 
## Matrix products: default
## BLAS/LAPACK: /opt/conda/lib/libopenblasp-r0.3.10.so
## 
## locale:
##  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
##  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
##  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
## [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] cowplot_1.1.0   magrittr_1.5    forcats_0.5.0   stringr_1.4.0  
##  [5] dplyr_1.0.2     purrr_0.3.4     readr_1.3.1     tidyr_1.1.2    
##  [9] tibble_3.0.3    ggplot2_3.3.2   tidyverse_1.3.0 Matrix_1.2-18  
## 
## loaded via a namespace (and not attached):
##  [1] tidyselect_1.1.0 xfun_0.18        haven_2.3.1      lattice_0.20-41 
##  [5] colorspace_1.4-1 vctrs_0.3.4      generics_0.0.2   htmltools_0.5.0 
##  [9] yaml_2.2.1       blob_1.2.1       rlang_0.4.7      pillar_1.4.6    
## [13] withr_2.3.0      glue_1.4.2       DBI_1.1.0        dbplyr_1.4.4    
## [17] modelr_0.1.8     readxl_1.3.1     lifecycle_0.2.0  munsell_0.5.0   
## [21] gtable_0.3.0     cellranger_1.1.0 rvest_0.3.6      evaluate_0.14   
## [25] knitr_1.30       fansi_0.4.1      broom_0.7.1      Rcpp_1.0.4.6    
## [29] scales_1.1.1     backports_1.1.10 jsonlite_1.7.1   farver_2.0.3    
## [33] fs_1.5.0         hms_0.5.3        digest_0.6.25    stringi_1.5.3   
## [37] grid_4.0.2       cli_2.0.2        tools_4.0.2      crayon_1.3.4    
## [41] pkgconfig_2.0.3  ellipsis_0.3.1   xml2_1.3.2       reprex_0.3.0    
## [45] lubridate_1.7.9  assertthat_0.2.1 rmarkdown_2.4    httr_1.4.2      
## [49] rstudioapi_0.11  R6_2.4.1         compiler_4.0.2

The GitHub issue @ManavalanGajapathy 在评论中指出的与我所经历的相同。总之,我开始使用的 Miniconda3 (Debian-based) Docker 容器不包含 R 可以在绘图中使用的字体。该线程讨论了在 Docker-level (apt-get) 和 Conda-level.

上安装字体的多个选项

我最终选择的解决方案是将依赖项 fonts-conda-ecosystem 添加到我的 Conda 环境中。现在的最终输出是: