r - 如何在 rmarkdown html_document 中对齐表格和绘图

标签 r ggplot2 r-markdown kable

如何在 rmarkdown html_document 中将 kable 表与 ggplot2 图对齐?

Foo.Rmd

---
title: "Foo"
output: html_document
---

```{r setup, include=FALSE}
library(ggplot2)
library(knitr)
library(kableExtra)
```

# Table next to plot
```{r echo = FALSE}
kable(head(iris)) %>%
  kable_styling(bootstrap_options = "striped", full_width = F)

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point()
```

enter image description here

我尝试遵循解决方案 here但无济于事。

最佳答案

@ErrantBard 在这里提供了一个很好的解决这个问题的方法:https://stackoverflow.com/a/40650190/645206 .请访问并点赞! 我正在复制我的答案中的解决方案,以展示它如何与您的示例一起工作,并提供解决方案的图像。

要更好地了解这些 div 标记的工作原理,请了解有关 Bootstrap 库的更多信息。这是一个很好的链接:https://getbootstrap.com/docs/4.1/layout/grid/

---
title: "Foo"
output: html_document
---

```{r setup, include=FALSE}
library(ggplot2)
library(knitr)
library(kableExtra)
```

# Table next to plot
<div class = "row">
<div class = "col-md-6">
```{r echo=FALSE}
kable(head(iris)) %>%
  kable_styling(bootstrap_options = "striped", full_width = FALSE, position="left")
```
</div>

<div class = "col-md-6">
```{r echo=FALSE}
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point()
```
</div>
</div>

enter image description here

关于r - 如何在 rmarkdown html_document 中对齐表格和绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54312894/

相关文章:

r - 对包含相同信息的行求和并删除其余行

r - 如何使用 facet_wrap 将 y 轴设置为等于 x 轴 geom_line

r - multi_line 不适用于 label_parsed?

r - 使用贝叶斯图绘制来自多个模型的后验参数估计

r - R Markdown 中带有 pdf_document 输出的表格和绘图之间的换行符

r - 在不影响 R 代码块输出的情况下,我可以在使用 Markdown 和 knitr 时更改 MS Word Normal 样式吗

vertical-alignment - 使用 R markdown 生成的投影仪演示中的垂直对齐

r - 在 R 中对数据表中的连续行进行分组

r - 模拟具有统一创新的 AR(1) 过程

R数据表: update join