【发布时间】:2020-12-22 06:00:49
【问题描述】:
下图是在 R 中生成的(没有任何问题),使用以下代码:
library(tidyverse)
library(extrafont)
loadfonts()
x <- rexp(100)
data.frame(info = x) %>%
ggplot() +
geom_histogram(aes(x = info), col = "red", fill = "red", alpha = 0.5) +
theme_minimal() +
theme(text = element_text(family="LM Roman 10"))
如您所见,绘图的字体设置为“LM Roman 10”,感谢post,我能够做到这一点,它在 R 中完美运行。
但是,当我尝试使用 RMarkdown 将图像放置在 LaTeX 文档中时,出现以下错误:
Quitting from lines 10-22 (min_example.Rmd)
Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
invalid font type
Calls: <Anonymous> ... drawDetails -> drawDetails.text -> grid.Call.graphics
Además: There were 50 or more warnings (use warnings() to see the first 50)
Ejecución interrumpida
这是min_example.Rmd的代码
---
title: "Untitled"
author: "Javier Rojas"
date: "2/9/2020"
output: pdf_document
---
```{r, echo=FALSE}
library(tidyverse)
library(extrafont)
loadfonts()
x <- rexp(100)
data.frame(info = x) %>%
ggplot() +
geom_histogram(aes(x = info), col = "red", fill = "red", alpha = 0.5) +
theme_minimal() +
theme(text = element_text(family="LM Roman 10"))
```
我使用的是运行 macOS High Sierra 和 R 3.6.1 的 Mac 计算机
【问题讨论】:
-
您安装了拉丁现代字体吗?见this,说明中有答案。
-
是的佩德罗,我有。代码在 R 中运行没有问题,当我将该代码放在 RMarkdown 块中时会出现问题
标签: r ggplot2 fonts r-markdown