问题
How can I align a kable table to be adjacent to a ggplot2 plot in an rmarkdown html_document?
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()
```
I tried following the solution here but to no avail.
回答1:
A great solution to this issue is provided here by @ErrantBard: https://stackoverflow.com/a/40650190/645206. Please visit and upvote it! I am copying the solution in my answer to show how it works with your example, and to provide an image of the solution.
To better understand how these div
tags work, learn more about the bootstrap library. Here is one good link: 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>
来源:https://stackoverflow.com/questions/54312894/how-to-align-table-and-plot-in-rmarkdown-html-document