use*_*089 9 r knitr r-markdown
在.Rmd文档中,有多种方法可以并排生成图形。如果人物已经存在,对我来说最简单的方法就是使用knitr::include_graphics(c(fig1, fig2, ...))[Thx: Yihui!]
但是当我这样做时,我找不到添加整体图形标题的方法,而在 LaTeX 中可以轻松完成。这是一个例子:
块
```{r, out.width = "30%", echo=FALSE}
# two figs side by side
include_graphics(c("fig/mathscore-data.png",
"fig/mathscore-data-ellipses.png"))
```
Run Code Online (Sandbox Code Playgroud)
输出:
如果我将 a 添加fig.cap到块选项,我会得到两个单独的图形,每个图形都有相同的图形标题。
```{r, out.width = "30%", echo=FALSE, fig.cap="Left: scatterplot of mathscore data; Right: Data ellipses for the two groups."}
# two figs side by side
include_graphics(c("fig/mathscore-data.png",
"fig/mathscore-data-ellipses.png"))
```
Run Code Online (Sandbox Code Playgroud)
还有其他方法可以做我想要的事情吗——两个并排的子图,有一个共同的标题?
use*_*545 13
在knitr中将块选项设置为:
echo=FALSE,out.width="49%",out.height="49%",fig.show='hold',
fig.align='center'
Run Code Online (Sandbox Code Playgroud)
我使用了乳胶包子标题,
在 YAML 标头的 header-includes 部分中导入。
---
title: "Untitled"
author: "V"
date: "22 4 2020"
output: pdf_document
header-includes:
- \usepackage{subcaption}
---
# add Two figures with latex
\begin{figure}[h]
\begin{subfigure}{.5\textwidth}
\includegraphics[]{CAT.png}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
\includegraphics[]{CAT.png}
\end{subfigure}
\caption{This is the main caption - Years 2020 - 2030 - the main caption. }
\end{figure}
# add Two figures with Knitr
```{r, echo=FALSE,out.width="49%",out.height="49%",fig.show='hold',
fig.align='center', fig.cap="This is the main caption - Years 2020 - 2030 - the main caption."}
knitr::include_graphics(c("CAT.png","CAT.png"))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8540 次 |
| 最近记录: |