当我使用自定义字体渲染ggplot时,它在IDE中可以工作,但是在Quarto和RMarkdown中,我一直收到这个错误:
Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
invalid font type
Calls: .main ... drawDetails -> drawDetails.text -> grid.Call.graphics
这些字体都已经安装在我的系统上,但是Quarto或RMakrdown并没有识别出来。
例如,这是我的脚本:
---
title: "TEST"
format: pdf
editor: visual
---
This plot works:
```{r echo=FALSE, message=FALSE, warning=FALSE}
library(tidyverse)
mtcars |>
count (cyl) |>
ggplot (aes (x = cyl, y = n)) +
geom_col() +
labs (title = "Plot 1") +
geom_text (aes (label = n),
vjust = -1)
```
This plot does not:
```{r echo=FALSE, message=FALSE, warning=FALSE}
mtcars |>
count (cyl) |>
ggplot (aes (x = cyl, y = n)) +
geom_col() +
labs (title = "Plot 2") +
geom_text (aes (label = n),
vjust = -1,
family = "Montserrat") +
theme (text = element_text(size = 12, family = "Montserrat"))
```
showtext
或extrafont
来显示自定义字体。您可能是在IDE中运行该代码而不是在Rmarkdown文档中运行? - MrFlicksource()
,因此问题并不完全可重现。也许可以将该代码直接包含在 Markdown 文件中作为示例。 - MrFlick