如何在rmarkdown中设置基础图形的默认字体?

问题描述 投票:0回答:1

我想在 rmarkdown 文档中设置基本图的默认字体,但我意识到它不起作用。 有谁知道如何在 rmarkdown (html) 中为基本图形设置默认字体

---                                                                                
title: "Setting font in par"                                                       
output: html_document                                                              
---                                                                                

The way of setting default font for base graphics is to use par
                                                                             
```{r}                                                                             
par(family = "monospace")                                                          
```                                                                                
                                                                                   
Setting the default does NOT work in Rmd while executing directly in terminal does
                                                                                   
```{r}                                                                             
plot(1:10, main = "title") # output of rmarkdown::render does not use the right font
                           # but execution in a terminal does                         
```                                                                                
                                                                                   
Specifying it explicitely does work                                                
                                                                                   
```{r}                                                                             
plot(1:10, main = "title", family = "monospace")                                   
```                                                                                
r r-markdown knitr
1个回答
0
投票

每个代码块都在单独的图形设备内进行评估,这意味着前一个块中的

par()
之类的设置不会传递到下一个块。如果你想让这些设置持久化,你需要设置选项:

knitr::opts_knit$set(global.device = TRUE)

请参阅 R Markdown Cookbook 中的本节了解更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.