Zizou
Zizou

Reputation: 503

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:

enter image description here

# 
# ---
#   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>   

Upvotes: 1

Views: 818

Answers (1)

Allan Cameron
Allan Cameron

Reputation: 173803

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:

enter image description here

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

Upvotes: 2

Related Questions