Rmarkdown:为情节添加标题

时间:2017-05-05 14:01:06

标签: r rstudio r-markdown caption

我正在使用Rmarkdown创建PDF文档。我有一个块,应该创建一个情节并添加一个标题。但是,当我添加fig.cap选项并包含echo = FALSE时,图表会在文档末尾打印而不是立即打印。

当编织为HTML时,标题类型有效,虽然格式很奇怪,但在PDF中,图表会附加到结尾。

```{r, warning=FALSE,echo = FALSE, message=FALSE, fig.cap = "test cap"}
## Basic plots
par(mfrow = c(3, 1))
plot(y = datas, x = as.Date(dates), type = "l",
     main = "N225", ylab = "value", xlab = "time",
     col = "salmon", frame = FALSE)
lines(y = datas[(length(datas) - 500):length(datas)],
      x = dates[(length(datas) - 500):length(datas)],
      col = "lightblue")
legend(y = 18000, x= as.Date('2015-01-01'),
       legend = c("Train", "Test"),
       col = c("salmon", "lightblue"),
       pch = 19)
plot(y = loret, x = as.Date(dates), type = "h",
     main = "N225 log-returns", ylab = "logreturns", xlab = "time",
     col = "salmon", frame = FALSE)
lines(y = loret[(length(loret) - 500):length(loret)],
      x = dates[(length(loret) - 500):length(loret)],
      col = "lightblue", type = "h")
plot(y = loret^2, x = as.Date(dates), type = "h",
     main = "N225 squared log-returns", ylab = "logreturn", xlab = "time",
     col = "salmon", frame = FALSE)
lines(y = (loret[(length(loret) - 500):length(loret)])^2,
      x = dates[(length(loret) - 500):length(loret)],
      col = "lightblue", type = "h")
```

我在HTML中获得的内容

What I get in HTML

我得到的PDF格式

What I get in PDF

0 个答案:

没有答案