R使用矩形绘制图形而不是文本

5
我正在使用snakemake构建管道,并使用condasingularity环境来确保可重复性。 我遇到了一个错误,我的绘图中的文本被替换为矩形enter image description here
在Linux和Mac系统上尝试使用该管道并禁用singularity容器后,似乎问题源于缺少字体库,因为当我仅在Mac上使用conda--use-conda)运行管道时,文本会正常绘制。
singularity容器是从使用Debian GNU / Linux的this miniconda docker镜像构建的。 我已经成功创建了一个最小的示例管道,在其中文本不会被绘制。
# Snakefile
singularity: "docker://continuumio/miniconda3"

rule all:
    input:
        "mtcars-plot.png"

rule plot_mtcars:
    output:
        "mtcars-plot.png"
    conda:
        "minimal.yaml"
    script:
        "mtcars-test.R"

# mtcars-test.R
library(ggplot2)
png("mtcars-plot.png")
ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot()
dev.off()

# minimal.yaml
channels:
    - bioconda
    - conda-forge
    - defaults
dependencies:
    - r-base =3.6
    - r-ggplot2

要绘制断点图,请运行管道。
snakemake --use-conda --use-singularity

我该安装哪些包/库才能在Debian GNU/Linux上正确绘制R文本?

3
似乎与此相关:https://github.com/ContinuumIO/anaconda-issues/issues/7455 你的机器上是否安装了字体?也似乎在这里讨论过:https://github.com/conda-forge/r-base-feedstock/issues/91 - MrFlick
感谢@MrFlick提供的链接,链接帮助解决了问题! - Tomas Bencomo
2个回答

7

感谢MrFlick的评论,第二个链接指出在R中需要mscorefonts软件包来支持文本。

mscorefonts添加到conda环境中即可解决该问题。

# minimal.yaml
channels:
    - bioconda
    - conda-forge
    - defaults
dependencies:
    - r-base =3.6
    - r-ggplot2
    - mscorefonts

1

conda config --set always_yes yes

conda config --add channels conda-forge

conda update --all

conda install r-ggplot2 r-rmarkdown

我运行了这些命令,问题得到了解决。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接