gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 13:01:39 26 4
gpt4 key购买 nike

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

在 Linux 和 Mac 系统上试验管道并禁用奇点容器后,问题似乎源于缺少字体库,因为当我仅使用 conda 运行管道时,文本会正常绘制> (--use-conda) 在我的 Mac 上。

奇点容器是由 this miniconda 构建的使用 Debian GNU/Linux 的 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 正确绘制文本可能会缺少哪些软件包/库?

最佳答案

感谢MrFlick的评论,第二个link说 R 中的文本支持需要 mscorefonts 包。

mscorefonts 添加到 conda 环境可修复该问题

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

关于R 用矩形而不是文本绘制绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60401617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com