2016-04-06 65 views
1

我在RStudio內使用knitr和dismo包。嘗試一下,因爲我可能無法使用gmap在R標記內的文本之後出現創建的圖。dismo使用knitr的情節之前有白色空間

下面是截圖 Example showing extra white space

這裏是可以用來重新創建[R標記的最低位。您需要安裝三個引用的軟件包。

我正在使用RStudio,並在此環境中執行knitr命令。

--- 
title: "gmap" 
output: html_document 
--- 
```{r setup, include=FALSE} 
knitr::opts_chunk$set(echo = TRUE) 
library(dismo) 
library(rgdal) 
library(XML) 
``` 
The plot should follow this text 
```{r plot, fig.align='left', echo=FALSE, message=FALSE} 
g = gmap('Australia') 
plot(g) 
``` 
and precede this. Try as I might, there is white space between the start text and the image which I cannot get rid of. 

我找不到任何方法來使用knitr指令來控制圖像的高度,Google沒有提供明顯的答案。有沒有人看過這個,可以提供任何建議?

編輯:我有一個解決方案,繪製到一個PNG文件,然後包括它。這避免了這個問題,但是笨重。

回答

1

在生成地圖的塊的標題中添加fig.keep='last'。看起來在調用函數gmap()期間生成了兩個數字。你可以看到,如果你看看html頁面的源代碼。我不知道何時何地生成空白圖像(knit(),gmap(),??)。但是選項fig.keep='last'應該只保留第二個數字(地圖)來解決問題。

```{r plot, echo=FALSE,results='asis', fig.keep='last', fig.align='right'} 
g = gmap('Italia') 
plot(g) 
``` 
+0

是的 - 這工程。謝謝! – awchisholm