R 用矩形而不是文本绘制图 [英] R Draws Plots with Rectangles Instead of Text

查看:43
本文介绍了R 用矩形而不是文本绘制图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm building a pipeline with snakemake and using conda and singularity environments to ensure reproducibility. I run into an error where the text on my plots is replaced by rectangles

在Linux和Mac系统上对管道进行了实验并禁用了奇点容器之后,问题似乎是由于缺少字体库而引起的,因为当我仅使用 conda (-use-conda )在我的Mac上.

After experimenting with the pipeline on Linux and Mac systems and disabling the singularity container, it appears the issue stems from a missing font library as the text is drawn normally when I only run the pipeline using only conda (--use-conda) on my Mac.

奇异容器由使用Debian GNU/Linux.我设法创建了一个最小的示例管道,该管道不会绘制文本.

The singularity container is built from this miniconda docker image that uses Debian GNU/Linux. I've managed to create a minimal example pipeline where the text doesn't get drawn.

# 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

要绘制折线图,​​请运行管道

To draw the broken plot, run the pipeline

snakemake --use-conda --use-singularity

在Debian GNU/Linux上使用R正确绘制文本时,我可能缺少哪些软件包/库?

What packages/libraries could I be missing to correctly draw text with R on Debian GNU/Linux?

推荐答案

感谢MrFlick的评论,第二个链接说,在R中支持文本需要 mscorefonts 包.

Thanks to MrFlick's comment, the second link says the mscorefonts package is needed for text support in R.

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

Adding mscorefonts to the conda environment fixes the issue

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

这篇关于R 用矩形而不是文本绘制图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆