本文介绍了如何在rmarkdown html_document中对齐表格和绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在rmarkdown html_document中对齐山墙表使其与ggplot2图相邻?

Foo.Rmd

  ---标题:"Foo"输出:html_document---```{r setup,include = FALSE}库(ggplot2)图书馆(针织)图书馆(kableExtra)```#剧情旁的桌子```{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()``` 

我尝试在

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.

解决方案

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>

这篇关于如何在rmarkdown html_document中对齐表格和绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 15:45