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

问题描述 投票:0回答:1

我正在使用snakemake构建管道,并使用condasingularity环境来确保可重复性。我遇到一个错误,我的绘图上的文本被矩形替换了enter image description here

[在Linux和Mac系统上对管道进行了实验并禁用了奇点容器后,由于仅在使用conda--use-conda)运行管道时才能正常绘制文本,因此问题似乎是由于缺少字体库引起的。在我的Mac上。

奇异性容器是使用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正确绘制文本,我可能缺少哪些软件包/库?

r linux pipeline snakemake singularity-container
1个回答
1
投票

由于MrFlick的评论,第二个link表示mscorefonts包对于R中的文本支持是必需的。

mscorefonts添加到conda环境可解决此问题

# minimal.yaml
channels:
    - bioconda
    - conda-forge
    - defaults
dependencies:
    - r-base =3.6
    - r-ggplot2
    - mscorefonts
© www.soinside.com 2019 - 2024. All rights reserved.