Skip to content
Prev 389087 / 398506 Next

ggsave() with width only

On 06/09/2021 11:06 a.m., Ivan Calandra wrote:
It's not much effort.  For example, the document below produces two PDF 
figures with different heights but the same width.    I called the 
document Untitled.Rmd, so the figures show up in 
Untitled_figures/figure-latex/fig1-1.pdf and 
Untitled_figures/figure-latex/fig2-1.pdf.

   ---
   title: "Untitled"
   author: "Duncan Murdoch"
   date: "06/09/2021"
   output:
     pdf_document:
       keep_tex: true
   ---

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

   ```{r fig1, fig.width=2, echo=FALSE}
   library(ggplot2)
   ggplot(mtcars, aes(carb, gear)) +
     geom_point()
   ```

   ```{r fig2, fig.width=2, echo=FALSE}
   ggplot(mtcars, aes(carb, gear)) +
     geom_point() +
     coord_fixed()
   ```