using ggplot and patchwork for pdf landscape document

I'm trying to create a .pdf landscape document. I have a bunch of visualizations and would like to use "patchwork" which seems like the easiest way to arrange the vizzes so it looks more like a dashboard. How do I get the vizzes formatted so they take up more space? The below example is very similar to what I'm getting. All of the pages would look better if there weren't so much whitespace. Any help is appreciated. Thanks!

R Markdown Code Below:

---
title: "patchwork"
author: "name"
date: "3/3/2020"
output:
  pdf_document: default
  html_document:
    df_print: paged
  'pdf_document: default': default
classoption: landscape
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(patchwork)

p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))

ggplot(mtcars) +
  geom_point(aes(mpg, disp)) +
  ggplot(mtcars) +
  geom_boxplot(aes(gear, disp, group = gear))

p3 <- ggplot(mtcars) + geom_smooth(aes(disp, qsec))
p4 <- ggplot(mtcars) + geom_bar(aes(carb))

p4 + {
  p1 + {
    p2 +
      p3 +
      plot_layout(ncol = 1)
  }
} +
  plot_layout(ncol = 1)

p1 + p2 + p3 + plot_layout(ncol = 1)

(p1 | p2 | p3) /
  p4

(p1 + (p2 + p3) + p4 + plot_layout(ncol = 1)) * theme_bw()

p1 + (p2 + p3) + p4 + plot_layout(ncol = 1) & theme_bw()

Thanks for the reprex

I would make a second chunk, outside of setup

{r, echo=TRUE, fig.width=10}
library ...

That helped with the width. I added fig.height=10 and that got rid of the extra space at the bottom of the page. Thank you! That was a nice and easy solution.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.