How to resize a ggplot2 scatterplot when knitted to pdf from Markdown

Hi everyone (first post so please let me know if question needs improving)

I am creating a report which includes lots of boxplots and scatterplots. I am finding that the report is getting excessively long due to the large size of the graphs.

In places I have used par(mfrow=c(2,2)) where applicable, however in this case I am just displaying a single graph and would like to reduce its size by half, keeping the aspect ratio.
I am knitting the Markdown file to a pdf

I have created a reproducible example:

---
title: "test1"
output: 
    pdf_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(ggplot2)
NewData<-mtcars
```
The following graph shows the relationship between horsepower and rear axle ratio
```{r}
ggplot(NewData,aes(hp,drat))+geom_point()
```

Thanks in advance

I am working from memory because I cannot test this answer on this computer. Have you tried passing values to the fit.width and fig.height arguments, like this -

```{r, fig.height = 4, fig.width = 5}
ggplot(NewData,aes(hp,drat))+geom_point()

2 Likes

Thank you, that has solved it. For clarity, could you not test this on a computer due to the example being incorrect or you did not have the software on your current computer?

I did not have the write software on the computer.

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