Knitr或RMarkdown Beamer中的表格和图形并排 [英] Tables and Figures side-by-side in Knitr or RMarkdown Beamer

查看:516
本文介绍了Knitr或RMarkdown Beamer中的表格和图形并排的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在RMarkdown/Knitr中创建Beamer Presentation幻灯片.在幻灯片中,我希望并排放置一个桌子和一个图,然后在下面放置一些文本.如代码所示,我只能尽我所能.我想在Hmisc表旁边放置密度图.

I am trying to create a Beamer Presentation slide in RMarkdown / Knitr . In the slide I would like to have a table and a figure placed Side-by-side , and then some more text underneath. I can only get as far as my attempt as shown in the code. I would like to have the density plot placed, next to the Hmisc Table.

我不使用Kable或xtable,因为我可以使用Hmisc对表进行更多控制.

I am not using Kable or xtable since I get more control over the tables with Hmisc.

此外,如何调整各个幻灯片中的文本特征(字体大小,类型,颜色)?

Also, How can I adjust the text characteristics (font-size, type, color) in the individual slides?

---
title: "BeamerTest1"
subtitle: Beamer Subtitle
author: "Author"

output:
  beamer_presentation:
    theme: CambridgeUS
    colortheme: "beaver"
    fonttheme: "structurebold"
---

## Slide with Table, Figure and Text

My topic for this slide 

\scalebox{0.35}{
```{r hmisc-table, echo=FALSE, message=FALSE, results='asis'}
library(Hmisc)
latex(head(mtcars), file='', table.env=FALSE, center='none')
```
}


```{r, echo=FALSE, fig.show='hold', fig.height=1, fig.width=2.5}
library(ggplot2)
mt <- ggplot(mtcars, aes(mpg)) + geom_density(alpha=.2, fill="#FF6666") +
  theme(axis.title.x = element_text(size=10),axis.text.x  = element_text(size=8),
        axis.title.y = element_text(size=10),axis.text.y  = element_text(size=8))
mt
```

- Here is some Bullet Text
- And some more
    - Subtext
    - More Subtext

谢谢

推荐答案

我已经回答了类似的问题一样,我重复我的回答,我使用:::表示法,添加代码以创建您可能想要的输出.

As I've already answered the similar question like this, I repeat my answer in which I use ::: notation, adding the codes to create the output you may want.

您可以使用 fenced_divs 表示法或:::来创建列或两个内容的布局".另请参见此页面进一步了解该符号.

You can use fenced_divs notation or ::: to create columns or `Two Content layout'. See also this page to know more about the notation.

## Slide With Image Left

::: columns

:::: column
left
::::

:::: column
right

```{r your-chunk-name, echo=FALSE, fig.cap="your-caption-name"}
knitr::include_graphics("your/figure/path/to/the-image.pdf")

#The figure will appear on the right side of the slide...
```
::::

:::

由于支持符号的pandoc 2+是在RStudio v1.2+中实现的,因此您可能需要安装 RStudio v1.2+ 首先.安装非常简单(至少在我的情况下);只需下载并安装RStudio v1.2+.在安装方式中,计算机上的RStudio先前版本将被新版本替换,而无需手动卸载.

Since pandoc 2+, which supports the notation, was implemented in RStudio v1.2+, you may need to install RStudio v1.2+ first. The installation is easy enough (at least in my case); just download and install RStudio v1.2+. In the way of installation, the former version of RStudio on your computer will be replaced with the new one without uninstalling it manually.

下图是实现该表示法的示例.

The following figure is an example which you have if you implement the notation.

产生上面幻灯片的MWE代码也在这里:

The MWE code which produced the slide above is here, too:

---
title: "BeamerTest1"
subtitle: Beamer Subtitle
author: "Author"

output:
  beamer_presentation:
  theme: CambridgeUS
  colortheme: "beaver"
  fonttheme: "structurebold"
---

## Slide with Table, Figure and Text

::: columns

:::: column

My topic for this slide 

\scalebox{0.35}{
```{r hmisc-table, echo=FALSE, message=FALSE, results='asis'}
library(Hmisc)
latex(head(mtcars), file='', table.env=FALSE, center='none')
```
}


```{r, echo=FALSE, fig.show='hold', fig.height=1, fig.width=2.5}
library(ggplot2)
mt <- ggplot(mtcars, aes(mpg)) + geom_density(alpha=.2, fill="#FF6666") +
theme(axis.title.x = element_text(size=10),axis.text.x  = element_text(size=8),
axis.title.y = element_text(size=10),axis.text.y  = element_text(size=8))
mt
```

::::

:::: column

- Here is some Bullet Text
- And some more
    - Subtext
    - More Subtext

::::

:::

这篇关于Knitr或RMarkdown Beamer中的表格和图形并排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆