如何在 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()
```
我尝试遵循解决方案 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>
关于r - 如何在 rmarkdown html_document 中对齐表格和绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54312894/