【发布时间】:2021-12-06 21:53:48
【问题描述】:
我正在尝试更新 rmarkdown 的 pdf 输出的边距。
这是我的代码:
---
title: "Analysis Report "
date: "Last edited `r format(Sys.time(), '%B %d, %Y')`"
geometry: "left=2cm,right=2cm,top=2cm,bottom=2cm"
output:
pdf_document:
toc: true
pandoc_args: [
"--number-sections",
"--number-offset=1"
]
---
```{r setup, include=FALSE}
library(naniar)
library(flexdashboard)
library(ggplot2)
library(rsconnect)
library(leaflet)
library(table1)
library(shiny)
library(DT)
library(readr)
library(kableExtra)
library(flextable)
library(expss)
library(tidyverse)
library(knitr)
library(plotly)
library(magrittr)
dfTab <- structure(list(x = structure(1:4, .Label = c("No, they do not agree", "Yes, they agree", "Unable to contact participant", "Undecided"),
class = "factor"), Freq = c(1L, 7L, 0L, 0L), lab = c("1 (12.5%)", "7 (87.5%)", "0 (0%)", "0 (0%)")),
row.names = c("No, they do not agree", "Yes, they agree", "Unable to contact participant", "Undecided"
), class = "data.frame")
\\```
\newpage
# Sample Graph
```{r, echo=FALSE,out.width='\\textwidth', fig.height = 7, fig.align='center', out.height="80%",out.width="80%"}
plot <- ggplot(dfTab, aes(x=x, y=Freq, fill=x)) +
geom_bar(width = 1, size = 1, stat = "identity") +
geom_text(aes(label=lab), vjust = -1)+
theme_classic() +
theme(#axis.text.x = element_text(size = 12, colour = "black"),
axis.line.x = element_line(),
axis.ticks.x = element_line(),
#axis.text.y = element_blank(),
#axis.line.y = element_blank(),
#axis.ticks.y = element_blank(),
#axis.text=element_text(size=12),
axis.title=element_text(size=12,face="bold"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position="top",
legend.title = element_blank())+
#scale_x_discrete(labels = abbreviate)+
labs(title="This is the title of the graph", x="", y="Count")
plot
请注意,我在上面代码中的 3 个刻度之前添加了“\”,以便 stackoverflow 编辑器识别我的代码。
反正输出文档是这样的
边距仍然太宽。我的代码有问题吗?我读过我必须在geometry: "left=2cm,right=2cm,top=2cm,bottom=2cm" 中声明边距大小,但它似乎不起作用。非常感谢任何帮助。
【问题讨论】:
-
在那里检查我的答案,也许有帮助:stackoverflow.com/questions/69689548/…
-
你好@manro,我的代码中已经有了上面讨论的几何规范,但我仍然看到很大的余量。
标签: r r-markdown