【问题标题】:Plots in dismo using knitr are preceded with white space使用 knitr 在 dismo 中的绘图前面带有空格
【发布时间】:2016-04-06 14:40:39
【问题描述】:

我在 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 文件,然后将其包含在内。这避免了这个问题,但很笨重。

【问题讨论】:

    标签: r rstudio r-markdown


    【解决方案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)
    ```
    

    【讨论】:

      猜你喜欢
      • 2014-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-28
      • 1970-01-01
      • 2019-03-25
      • 1970-01-01
      • 2012-10-02
      相关资源
      最近更新 更多