I have made a PDF from an Rmarkdown file.
I wish to make the pdf in landscape mode so that it occupies the full screen.
The landscape mode works but it does not occupy the full screen. I have read this article which recommends setting aspectratio=169. This is what I am unable to do.
Here is a reproducible example:
---
title: "Testing landscape and aspect ratio"
output:
pdf_document:
number_sections: true
classoption:
- landscape
- "aspectratio=169"
header-includes:
- usepackage{dcolumn}
documentclass: article
geometry: margin=1.5cm
---
```{r}
plot(rnorm(100))
```
I have tried only classoption: landscape
. That does make it landscape but does not occupy the full screen.
Here is a screenshot of the output:
Here is my session info():
> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 11 (bullseye)
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.13.so; LAPACK version 3.9.0
locale:
[1] LC_CTYPE=en_IN LC_NUMERIC=C LC_TIME=en_IN
[4] LC_COLLATE=en_IN LC_MONETARY=en_IN LC_MESSAGES=en_IN
[7] LC_PAPER=en_IN LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_IN LC_IDENTIFICATION=C
time zone: Asia/Kolkata
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.43
loaded via a namespace (and not attached):
[1] compiler_4.3.1 tools_4.3.1 xfun_0.39
>
Update: My R version has changed but the output from this code is still the same.
Here is my new sessionInfo():
> sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 11 (bullseye)
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.13.so; LAPACK version 3.9.0
locale:
[1] LC_CTYPE=en_IN LC_NUMERIC=C LC_TIME=en_IN
[4] LC_COLLATE=en_IN LC_MONETARY=en_IN LC_MESSAGES=en_IN
[7] LC_PAPER=en_IN LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_IN LC_IDENTIFICATION=C
time zone: Asia/Kolkata
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.3.2
>
2
Answers
You could use
out.extra='keepaspectratio=true'
chunk options. See this post: "% are translated to scaling factors to textheight and linewidth)"Result:
Because this is a base-R plot, you could do some of what you want more easily by controlling some
par()
settings. For example, to avoid extra space around the plot, use