使用 knitr 的 dismo 中的绘图前面带有白色 space

Plots in dismo using knitr are preceded with white space

我在 RStudio 中使用 knitr 和 dismo 包。尽我所能,我无法让使用 gmap 创建的绘图立即出现在 R 标记中的文本之后。

这是截图

这里有一小段 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 文件然后包含它。这避免了这个问题,但很笨重。

在生成地图的块的头部添加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)
```