I have a report that takes ggplot2 plots and outputs them in a PDF using RMarkdown and Latex. The first page is a plot that is best displayed in landscape mode and the rest of the report are plots to be displayed in portrait mode. The report has no title page, has a header and a footer with the page number.
I'm looking for the MWE below to outputted as a pdf with the Iris plot in landscape, the lipsum text in portrait mode, and the header to be at the top of the page on both pages, the page number in the bottom right of both pages, and no blank first page.
I have played with this before and have never found a quite satisfactory answer on here. Reasons being one or more of the following:
- Since the first (and only first) page is in landscape, some kind of
\begin{landscape}command always inserts a blank first page (with page number 1) at the beginning of the doc. It's my understanding that\begin{landscape}inserts a page break and this does not interact well with\AtBeginDocument{\let\maketitle\relax} - The header ends up being rotated such that the header is now a vertical line on the right side of the page. This would be preferred if the report was meant to be printed & stapled together but that's not what I'm looking for. I want the header to still be at the top of the page no matter the orientation.
- Closest I've gotten is using the
\typeareapackage and\KOMAoptions, however the widths of the ggplot graph on the landscape page are still the same width as if the page was in portrait mode (the graph does not resize to take advantage of the extra space).
Any thoughts/help would be much appreciated! Here is a MWE to get you set up:
MWE Markdown .Rmd document:
---
title: "Landscape Orientation Demo"
author: ""
date: "10/31/2021"
output:
pdf_document:
latex_engine: xelatex
includes:
in_header: "preamble.tex"
classoption: landscape
header-includes:
\AtBeginDocument{\let\maketitle\relax}
---
```{r setup, include=FALSE}
library(ggplot2)
knitr::opts_chunk$set(echo = FALSE, warning=FALSE,message = FALSE)
```
```{r iris plot, fig.dim=c(11,8.5), results="asis"}
ggplot(data=iris, aes(x=Sepal.Width,y=Sepal.Length,color=Species)) +
geom_point()
```
\newpage
\lipsum
And the preamble.tex file is:
% Set up Headers/Footers
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{Header Title}
\fancyhead[R]{\today}
\fancyfoot[R]{\thepage}
% Sample text
\usepackage{lipsum}