简体   繁体   English

如何在R降价中删除图形之间的空白空间

[英]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.问题可能出在html结构上,我不太清楚。 I tried to use fig.align = 'left' but it doesn't work.我尝试使用fig.align = 'left'但它不起作用。 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 添加style标记来向下移动表格以减少间隙:

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

and do something similar to the div that holds your plot:并执行类似于保存您的情节的 div 的操作:

<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.您可以通过这种方式添加您喜欢的任何其他 css 样式调整来移动元素,调整它们的大小/颜色等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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