HTML中的Knitr和Figure标题

HTML中的Knitr和Figure标题,r,ggplot2,knitr,r-markdown,R,Ggplot2,Knitr,R Markdown,knitr将参数fig.cap定义为 fig.cap:(空;字符)图形中要使用的图形标题 乳胶中的环境(在\caption{});如果为NULL或NA,则为 忽略,否则图形环境将用于中的绘图 区块(在\begin{figure}和\end{figure}中输出) 但是,对于HTML输出,以下工作: --- title: "Caption Test" author: "Some Author" date: "February 18, 2016" output: html_document ---

knitr将参数fig.cap定义为

fig.cap:(空;字符)图形中要使用的图形标题 乳胶中的环境(在\caption{});如果为NULL或NA,则为 忽略,否则图形环境将用于中的绘图 区块(在\begin{figure}和\end{figure}中输出)

但是,对于HTML输出,以下工作:

---
title: "Caption Test"
author: "Some Author"
date: "February 18, 2016"
output: html_document
---

```{r}
library(ggplot2)
```

```{r, fig.cap = c("This is caption 1", "This is caption 2")}
## Plot 1
qplot(carat, price, data = diamonds)

## Plot 2
qplot(carat, depth, data = diamonds)
```
也就是说,每个图都在代码块参数
fig.cap=c(“caption 1”、“caption 2”)


然而,当标题放在块选项中时,跟踪标题是一项挑战,特别是如果标题很长的话。除了为每个图形创建两个单独的块,并在块外插入标题外,还有其他选项吗

您可以设置
eval.after=“fig.cap”
,以便在运行区块后计算图形标题。这样,您就可以在块中定义标题

---
title: "Caption Test"
author: "Some Author"
date: "February 18, 2016"
output: html_document
---

```{r}
library(ggplot2)
library(knitr)
opts_knit$set(eval.after = 'fig.cap')
```

```{r, fig.cap = cap}
## Plot 1
qplot(carat, price, data = diamonds)
cap <- "This is caption 1"

## Plot 2
qplot(carat, depth, data = diamonds)

cap <- c(cap, "This is caption 2")
```
---
标题:“字幕测试”
作者:“某个作者”
日期:“2016年2月18日”
输出:html\u文档
---
```{r}
图书馆(GG2)
图书馆(knitr)
选择针织$set(eval.after='fig.cap')
```
```{r,fig.cap=cap}
##地块1
qplot(克拉、价格、数据=钻石)

cap这将是下一版本knitr中的默认值: