2016-01-25 30 views
0

我想修復我在RMarkdown中的情節(通過使用RStudio),使它在PDF報告中呈現爲一個正方形。如何修復ggplot中的正方形以獲得PDF報告?

我RMarkdown腳本:

--- 
header-includes: \usepackage{graphicx} 
output: 
    pdf_document: 
     keep_tex: true 
--- 

```{r results='hide', message=FALSE, warning=FALSE, echo=FALSE} 
library(ggplot2) 

minX <- min(iris$Sepal.Length) # 4.3 
maxX <- max(iris$Sepal.Length) # 7.9 
minY <- min(iris$Sepal.Width) # 2.0 
maxY <- max(iris$Sepal.Width) # 4.4 

# 7.9 - 4.3 = 3.6. Extend the y range by 0.5 * (3.6 - 2.4) = 0.6 

minY <- minY - 0.6 
maxY <- maxY + 0.6 

scatter <- ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width)) 
scatter <- scatter + geom_point() 
scatter <- scatter + xlim(minX, maxX) 
scatter <- scatter + ylim(minY, maxY) 
#scatter <- scatter + coord_fixed() 
scatter 
``` 

我的PDF報告是這樣的。這顯然不是一個正方形:

enter image description here

如果我取消了coord_fixed()線在我的[R腳本,我得到這樣的:

enter image description here

現在,這是一個正方形的,但它浪費了水平空間,而且非常小。如何正確地做到這一點?

+0

如果您對圖形格式感到滿意,那麼尺寸只是指定針織塊中較大寬度的問題。 – baptiste

+0

@baptiste請你詳細說明一下嗎?我不太明白。 – SmallChess

回答

1

你可以告訴knitr做出更大的數字,例如

```{r width=7,out.width="7in"} 
... 
```