Skip to content

Plots with fixed fig.width are rendered differently in rstudio and knitr output #4913

Open

Description

@MaxKman

Hi,

thanks for developing R studio!

System details

RStudio Edition : Desktop
RStudio Version : Version 1.2.1335
OS Version : MacOS Mohave 10.14.3
R Version: 3.5.1

Steps to reproduce the problem

In a new rmarkdown document I use the following code:

---
title: "R Notebook"
output:
  html_document:
    df_print: paged
  pdf_document: default
---

```{r, eval = T, fig.asp=1.5, fig.width = 3.5}
library(tidyverse)
starwars %>% ggplot(aes(mass, height)) + geom_point(size = 1, shape = 16) + facet_wrap(~homeworld, ncol = 6) + theme(text = element_text(size = 8))```

to produce a plot with a fixed width and aspect ratio in rstudio
image

When knitting to html (or any other format I tried) the same plot is rendered differently, although the dimensions should be fixed here as well:
image

When comparing the image sizes the device size used in the html seems to have exactly half the width and height of the one used in the interactive notebook session in r studio.

If I add the following chunk to the beginning of my markdown document

```{r, setup, include=FALSE, eval = FALSE}
knitr::opts_chunk$set(fig.width = 3.5, fig.height = 2.5)```

and remove the fig.width argument from the actual chunk with the plot I get the exact same figure in rstudio and in the knitted html. I think this is the case because I set the figure dimensions in rstudio to half the standard values for rmarkdown without changing the values for the knitted document.

Describe the problem in detail

Just as a bit of background: My actual usecase is documenting data since analyses with bookdown. Rendering the chapters can take pretty long so I'd be a big time saver to get the plot dimensions right interactively in rstudio without having to render to see the results. For now I can get mostly around the problem with the mentioned setup chunk but in some cases I want a plot to have a higher fig.width and with the current behavior I can't really set this for each chunk separately.

Describe the behavior you expected

Plots with fixed dimensions in the interactive r studio notebook environment should have the same dimensions when knitted to an output format.

Thanks for your time, help appreciated!

Best Max

Activity

  1. ronblum commented on Jun 7, 2019

    @ronblum
    Contributor

    @MaxKman Thank you for raising this. It looks like a duplicated of #4521, but I'll reference your detailed analysis there. And, you're welcome!

  2. added this to the Cherry Blossom milestone on Dec 2, 2022
  3. ronblum commented on Dec 2, 2022

    @ronblum
    Contributor

    Moving to Cherry Blossom, in order to verify that it's fixed by PR #12324. If it's not, we'll reassign it to the current milestone. (Even though this is a duplicate, I'm including it in the list.)

  4. reopened this on Dec 2, 2022
  5. self-assigned this
    on Feb 6, 2023
  6. jonvanausdeln commented on Feb 6, 2023

    @jonvanausdeln

    I tested with 2023.03.0-daily+280 and this does not appear to be fixed. Moving back to triage to prioritize.

  7. modified the milestones: Backlog-1, Backlog on Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions