r - 如何在 rmarkdown html_document 中对齐表格和绘图
问题描述
如何将 kable 表与 rmarkdown html_document 中的 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()
```
我尝试按照此处的解决方案进行操作,但无济于事。
解决方案
@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>
推荐阅读
- python - 使用 pyfmi 库在 python 中加载 fmu 时出错
- excel - 为什么现在删除重复项会引发错误?
- c# - 在独木舟配置模拟中自动生成节点
- python - 如果正则表达式找不到匹配项,则返回“错误”
- mongodb - 如何用本地数据填充 dockerized MongoDB?
- android - 我无法让我的 android 应用在 react-native 上运行
- laravel - 如何在 wheres 数组中使用运算符
- reactjs - 如果未登录 React Token auth,则无法重定向
- html - 如何更改固定行高
- java - org.hidetake.groovy.ssh.session.BadExitStatusException