简体   繁体   中英

How to remove empty space between graphs in R markdown

I would like to remove long distances between objects and align the second graph to the left. The problem probably lies in the html structure, which I do not know too well. I tried to use fig.align = 'left' but it doesn't work. Below is my sample:

在此处输入图片说明

# 
# ---
#   output: html_document
# ---
#   ### TITLE
#   <div class = "row">
#     <div class = "col-md-6">
#       ```{r echo=FALSE, message=FALSE, warning=FALSE}
#     library(knitr)
#     library(readxl)
#     library(tibble)
#     library(dplyr)
#     library(kableExtra)
#     library(plotly)
#     
#     dt <- mtcars[1:5, 1:6]
#     dt %>%
#       kable() %>%
#       kable_styling()
#     
#     ```
#     </div>
#       <div class = "col-md-6">
#       ```{r echo=FALSE, message=FALSE}
#     plot_ly(
#       x = c("giraffes", "orangutans", "monkeys"),
#       y = c(20, 14, 23),
#       name = "SF Zoo",
#       type = "bar",
#       height = 300, width = 400
#     )
#     ```
#     </div>
#       </div>
#       ### TITLE
#       <div class = "row">
#       <div class = "col-md-6">
#       ```{r echo=FALSE, message=FALSE}
#     plot_ly(
#       x = c("giraffes", "orangutans", "monkeys"),
#       y = c(20, 14, 23),
#       name = "SF Zoo",
#       type = "bar",
#       height = 300, width = 400
#     )
#     ```
#     </div>
#       <div class = "col-md-6">
#       ```{r echo=FALSE, message=FALSE}
#     dt <- mtcars[1:5, 1:6]
#     dt %>%
#       kable() %>%
#       kable_styling()
#     ```
#     </div>
#       </div>   

You can move the table down to reduce the gap by adding a style tag to the div it sits in:

<div class = "col-md-6" style = "margin-top:60px;">

and do something similar to the div that holds your plot:

<div class = "col-md-6" style = "margin-left:-60px;">

That gives the following result:

在此处输入图片说明

You can add any other css styling tweaks you like in this way to move the elements around, adjust their size / colour etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM