减少Rmd PDF中ggplot和标题之间的空白

减少Rmd PDF中ggplot和标题之间的空白,r,ggplot2,latex,r-markdown,R,Ggplot2,Latex,R Markdown,我使用ggarrange在RMD PDF中绘制了以下两个图。它们很好,但我对标题和实际情节之间的巨大空白感到有点恼火。有什么办法可以减少这个空间吗 --- title: Report author: My Name date: "`r format(Sys.Date() - 30, '%B %Y')`" params: logo: logo.jpg cover: cover.png iblue: 6d1d26 igray: ffffff documentcla

我使用
ggarrange
在RMD PDF中绘制了以下两个图。它们很好,但我对标题和实际情节之间的巨大空白感到有点恼火。有什么办法可以减少这个空间吗

---
title: Report
author: My Name
date: "`r format(Sys.Date() - 30, '%B %Y')`"
params:
  logo: logo.jpg
  cover: cover.png
  iblue: 6d1d26
  igray: ffffff
documentclass: article
classoption: 
  - twocolumn
fontsize: 15
papersize: a4paper
output: 
  IReports::businessReport:
    keep_tex: TRUE
    latex_engine: xelatex
    resetStyleFiles: FALSE
header-includes: 
  - \newcommand{\logo}{`r gsub("_", "\\_", params$logo)`}
  - \newcommand{\cover}{`r gsub("_", "\\_", params$cover)`}
  - \newcommand{\iblue}{`r params$iblue`}
  - \newcommand{\igray}{`r params$igray`}
  - \usepackage{floatrow}
  - \floatsetup[figure]{capposition=top}
  - \floatsetup[table]{capposition=top}
include-before:
  - \renewcommand{\contentsname}{Contents Page}
  - \renewcommand{\pagename}{Page}
---

```{r setup, include = FALSE}
# packages
library(dplyr)
library(knitr)
library(xtable)

# settings
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
```


```{r fig6, fig.align='center', fig.cap="Currency (left) and Asset (Right) Allocation \\label{Figure6}", fig.width=5,fig.height=3, fig.pos='!h'}

library(tidyverse)
library(ggpubr)

# Dataframes

currency_breakdown <- structure(list(Currency = structure(1:4, .Label = c("ZAR", "USD", 
"EUR", "Other"), class = "factor"), `Percent (%)` = c(52.25, 
41.87, 3.11, 2.77), Key = c("ZAR [52.25%]", "USD [41.87%]", "EUR [3.11%]", 
"Other [2.77%]")), row.names = c(NA, -4L), class = c("tbl_df", 
"tbl", "data.frame"))

asset_breakdown <- structure(list(Asset = structure(c(4L, 3L, NA, 1L), .Label = c("Cash", 
"Money Market Securities", "Treasuries", "Agencies & Supras"), class = "factor"), 
    `Percent (%)` = c(1.02, 34.61, 33.06, 31.31), Key = c("Agencies & Supras [1.02%]", 
    "Treasuries [34.61%]", "Money Market [33.06%]", "Cash [31.31%]"
    )), row.names = c(NA, -4L), class = c("tbl_df", "tbl", "data.frame"))

# Plots

currency_breakdown_plot <- ggplot(currency_breakdown, aes("", `Percent (%)`, fill = Key)) + 
  geom_bar(stat = "identity", color = "white", size = 1) +
  coord_polar(theta = "y") +
  scale_fill_manual(values = c('#063A5B','#bbacaf','#c7af76','#7c3042')) +
  labs(colour = NULL) +
  theme_void() +
  theme(legend.position = c(.5,0),legend.title = element_blank(),
        legend.text=element_text(size=7)) +
  guides(fill = guide_legend(nrow = 2, override.aes = list(size = 1)))

asset_breakdown_plot <- ggplot(asset_breakdown, aes("", `Percent (%)`, fill = Key)) + 
  geom_bar(stat = "identity", color = "white", size = 1) +
  coord_polar(theta = "y") +
  scale_fill_manual(values = c('#063A5B','#bbacaf','#c7af76','#7c3042'),
                    labels = function(x) str_wrap(x, width = 20)) +
  labs(colour = NULL) +
  theme_void() +
  theme(legend.position = c(.5,0),legend.title = element_blank(),
        legend.text=element_text(size=7)) +
  guides(fill = guide_legend(nrow = 2,override.aes = list(size = 1)))

# ggarrange

ggarrange(currency_breakdown_plot, asset_breakdown_plot, nrow = 1)

```

---
标题:报告
作者:我的名字
日期:“`r格式(Sys.date()-30,'%B%Y')`”
参数:
logo:logo.jpg
封面:cover.png
iblue:6d1d26
伊格雷:ffffff
文档类:文章
类别选项:
-两列
尺寸:15
纸张尺寸:A4张
输出:
IReports::businessReport:
保持沉默:是的
乳胶引擎:Xeletex
resetStyleFiles:FALSE
标题包括:
-\newcommand{\logo}{`r gsub(“\\”,“\\\”,params$logo)`}
-\newcommand{\cover}{`r gsub(“\\”,“\\\”,params$cover)`}
-\newcommand{\iblue}{`r参数$iblue`}
-\newcommand{\igray}{`r参数$igray`}
-\usepackage{floatrow}
-\floatsetup[图]{capposition=top}
-\floatsetup[表]{capposition=top}
包括:
-\renewcommand{\contentsname}{Contents Page}
-\renewcommand{\pagename}{Page}
---
```{r设置,include=FALSE}
#包裹
图书馆(dplyr)
图书馆(knitr)
图书馆(xtable)
#背景
knitr::opts_chunk$set(echo=FALSE,message=FALSE,warning=FALSE)
```
```{r fig6,fig.align='center',fig.cap=“货币(左)和资产(右)分配\\标签{Figure6}”,fig.width=5,fig.height=3,fig.pos='!h'}
图书馆(tidyverse)
图书馆(ggpubr)
#数据帧

货币细分您可以使用
ggplot
中的
主题
选项。接下来,您可以将其添加到代码中:
plot.margin=unit(c(-0.20,0,0,0),“null”)

更改代码:

asset_breakdown_plot <- ggplot(asset_breakdown, aes("", `Percent (%)`, fill = Key)) + 
  geom_bar(stat = "identity", color = "white", size = 1) +
  coord_polar(theta = "y") +
  scale_fill_manual(values = c('#063A5B','#bbacaf','#c7af76','#7c3042'),
                    labels = function(x) str_wrap(x, width = 20)) +
  labs(colour = NULL) +
  theme_void() +
  theme(legend.position = c(.5,0),legend.title = element_blank(),
        legend.text=element_text(size=7), plot.margin=unit(c(-0.20,0,0,0), "null")) +
  guides(fill = guide_legend(nrow = 2,override.aes = list(size = 1)))

# ggarrange

ggarrange(currency_breakdown_plot, asset_breakdown_plot, nrow = 1)

asset\u-breakdown\u-plot能否将代码重新格式化为rmarkdown文档,同时提供YAML标题和区块选项?我们需要这些信息来检查预期结果是否正确。嗨@teunbrand,我现在编辑了它完美的解决方案!谢谢@bttomio