首页 > 解决方案 > 使用markdown转PDF时ggplot的问题

问题描述

当我在 Rstudio 的控制台中运行它时,我的绘图似乎没有任何问题,但是当我尝试使用 Rmarkdown 获取 PDF 输出时,代码会出现错误:

library(tidyverse)

mtcars %>% ggplot(aes(x = mpg, y = cyl)) + geom_line() +
  hrbrthemes::theme_modern_rc() +
  labs(title = "Plot")

在此处输入图像描述

这是错误:

grid.Call.graphics 中的错误(C_text, as.graphicsAnnot(x$label), x$x, x$y, : invalid font type Calls: ... drawDetails -> drwDetails.text -> grid.Call.graphics Además : 有 50 个警告(使用 warningswarnings() 查看第 50 个) Ejecución interrumpida

在 grid.Call(C_textBounds, as.graphicsAnnot(x$label), ... : 在 Windows 字体数据库中找不到字体系列

我怎么解决这个问题?

标签: rggplot2plotr-markdownthemes

解决方案


正如 henrik_ibsen 所说,解决方案是将 dev = "cairo_pdf" 添加到块选项中


推荐阅读