2017-05-30 30 views
1

根據documentationfig.retinaknitr中的默認值是1的數值。然後,我預計將設置保留爲空(例如下面的示例1 )將產生與下面的示例2完全相同的圖像,其中我指定fig.retina=1。相反,我發現默認(#1)創建一個60kb的圖像,並設置fig.retina=1產生一個25kb的圖像。在`knitr`塊中使用`fig.retina`會導致意想不到的數字尺寸

也許明確設置fig.retina覆蓋其他設置或東西?有沒有人有解釋爲什麼留空塊選項空白的結果是一個數字超過設置fig.retina=1(這應該是默認值)的兩倍?

--- 
title: "Untitled" 
output: 
    html_document: 
    self_contained: false 
--- 

```{r onefile_figretinaDefault} 
#1. this is 60kb on disk 
library(ggplot2) 
ggplot(cars, aes(speed, dist)) + geom_point() 
``` 


```{r onefile_figretina1, fig.retina=1 } 
#2. this is 25kb on disk 
ggplot(cars, aes(speed, dist)) + geom_point() 
``` 


```{r onefile_figretina2, fig.retina=2 } 
#3. this is 60kb on disk 
ggplot(cars, aes(speed, dist)) + geom_point() 
``` 


```{r onefile_figretinaNULL, fig.retina=NULL} 
#4. this is 25kb on disk 
ggplot(cars, aes(speed, dist)) + geom_point() 
``` 

```{r onefile_figretina1_owNULL, out.width = NULL, fig.retina=1 } 
#5. this is 25kb on disk 
ggplot(cars, aes(speed, dist)) + geom_point() 
``` 

回答

1

knitr文檔有點誤導。 將默認設置爲不同的值。例如,我在HTML文檔中看到默認值爲2。

您可以看到默認的是一大塊內印刷的價值是什麼:

knitr::opts_chunk$get("fig.retina") 

會給你默認,並

knitr::opts_current$get("fig.retina") 

會給你的當前值。

如果你看一下knitr源代碼(這是在Github上),你可以看到,默認爲1(這樣的文件是正確的),但如果你看看文檔(或源),很多的輸出設備(例如html_document)會改變它。

+0

是的,令人困惑!感謝您的澄清。 – ZRoss

+0

我同意這些差異是令人困惑的,但它們仍然記錄在案:http://rmarkdown.rstudio.com/authoring_migrating_from_v1.html –

相關問題