Skip to content

Inline plots display in incorrect size when figure dimension is given #2262

Open

Description

@netique

Not sure if the issue pertains rmarkdown, knitr or even RStudio more, but plot display inside .Rmd documents seems wrong, or unexpected at least. The output (no matter what format) is 100% correct and fulfils my expectation and so does the inline display in an R Markdown document in RStudio (with default options). However, when I define a custom chunk option in the chunk header, suddenly, it renders too small and fills the source pane width (see the GIF below). knitr::opts_chunk$set(fig.asp = .5) also leads to the same beahviour. It seems that when I create a custom output format with the exact options and use it inside the YAML header, plots do display normally.

rmd_reprex

.Rmd content:

---
title: "Untitled"
output: html_document
---

```{r pressureDefault}
plot(pressure)
```

```{r pressureFigAsp, fig.asp=.5}
plot(pressure)
```

Session info

xfun::session_info("rmarkdown")
#> R version 4.1.2 (2021-11-01)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 22000)
#> 
#> Locale:
#>   LC_COLLATE=Czech_Czechia.1250  LC_CTYPE=Czech_Czechia.1250   
#>   LC_MONETARY=Czech_Czechia.1250 LC_NUMERIC=C                  
#>   LC_TIME=Czech_Czechia.1250    
#> 
#> Package version:
#>   base64enc_0.1.3 digest_0.6.29   evaluate_0.14   fastmap_1.1.0  
#>   glue_1.5.1      graphics_4.1.2  grDevices_4.1.2 highr_0.9      
#>   htmltools_0.5.2 jquerylib_0.1.4 jsonlite_1.7.2  knitr_1.36     
#>   magrittr_2.0.1  methods_4.1.2   rlang_0.4.12    rmarkdown_2.11 
#>   stats_4.1.2     stringi_1.7.6   stringr_1.4.0   tinytex_0.35   
#>   tools_4.1.2     utils_4.1.2     xfun_0.28       yaml_2.2.1     
#> 
#> Pandoc version: 2.14.0.3

Created on 2021-12-20 by the reprex package (v2.0.1)

Checklist

When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:

  • formatted your issue so it is easier for us to read?

  • included a minimal, self-contained, and reproducible example?

  • pasted the output from xfun::session_info('rmarkdown') in your issue?

  • upgraded all your packages to their latest versions (including your versions of R, the RStudio IDE, and relevant R packages)?

  • installed and tested your bug with the development version of the rmarkdown package using remotes::install_github("rstudio/rmarkdown")?

Activity

  1. cderv commented on Dec 21, 2021

    @cderv
    Collaborator

    HI @netique ,

    I am sorry but I am not sure to have grasp what the issue is despite your GIF. Is this an issue with the inline plots below each chunk ? Or in the viewer with the resulting document ?

    However, when I define a custom chunk option in the chunk header

    What is the custom option in your example ? This is an example with fig.asp only here, right ?

    it renders too small and fills the source pane width (see the GIF below).

    Do you mean that inline image width is recalculated while your reduce the source pane window width ?

    Thanks for the additional precision you can provide.

  2. netique commented on Dec 21, 2021

    @netique
    Author

    Hi @cderv,

    Is this an issue with the inline plots below each chunk ?

    Exactly. The first renders fine, but the second behaves unexpectedly. Note that the content is the same, only the second chunk possess fig.asp option (fig.width and fig.height also do the trick, even when you use the defaults).

    The output document is OK, the second plot has aspect ratio as requested; font size and width stays the same for both, as expected. Not so in the Source pane, though.

    Maybe it's about screen DPI, I have two monitors with 4K and FHD, 4K being the main one. RStudio and Qt version used in RStudio have been experiencing DPI/scale issues at multidisplay systems AFAIK.

  3. cderv commented on Dec 21, 2021

    @cderv
    Collaborator

    If this is an issue with the way plots are resized in the inline output of the source pane for Rmd document, this would belong into the RStudio IDE repo. I really don't know if they respect the fig.asp option and what is done to resize the image while the window is resized. What I know is that they deal with inline image size in the IDE and that it is / will be different than the one in resulting document produced by rmarkdown. I think it is by convenience for a good user experience when previewing the document content inline.

    It would be best to share with IDE team there. Would you mind reopening one there following there issue guide ?
    https://github.com/rstudio/rstudio/wiki/Writing-Good-Bug-Reports

    thanks !

  4. added
    RStudio IDE
    on Dec 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    RStudio IDE

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions