You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Figure size in RStudio is different than in rendered output #4521
Knit the document to see the output in the rendered HTML.
Describe the problem in detail
The size of the figure in the RStudio interface is different than the size in the rendered output.
I spent time trying to adjust the fig.width and fig.height so the figure looks good when I run the chunk in RStudio.
It turns out my time is wasted because the rendered output does not use the same figure size as the figured in RStudio (see screenshot below).
Questions
How are users supposed to size their figures properly?
Are we meant to re-knit the file each time we tweak the fig.width and fig.height parameters?
If so, notice that the user must ignore the output as shown in RStudio while tweaking chunk options, since they will never share RStudio output with others and it is not representative of the knitted output.
Reacted by MaxKman, Jan Broder Engler, Jan Gleixner, A. Solomon Kurz, Lluís Revilla, Milan Bouchet-Valat, Charles Li, Christopher Ball, Frederik Aust, Matti Vuorre and 3 more
The size of the plots in RStudio will also change if you resize the panel, if you click zoom, etc. How else would you expect it to work? you're not setting a pre-defined size in terms of pixels for your plot in there.
RStudio ignores dpi, but respects fig.width and fig.height
It seems that RStudio ignores the dpi option, but it respects the fig.width and fig.height options. This is not expected behavior.
If RStudio respects fig.width and fig.height, then I also expect it to respect dpi.
The two output devices are different
After trying a few more examples, I cannot get the output in the RStudio document to look the same as the output in the knitted document.
I guess the graphics devices and their settings are different for the two outputs. I would have expected them to be more similar.
This leaves the user in an undesirable situation:
The user cannot predict the appearance of the rendered output without knitting the document.
RStudio misleads the user to think the knitted document will look like the RStudio document. Then the user will be surprised when the output does not match what they saw while writing code and tweaking the chunk options.
Confusingly, the user must remember that a poor output in the RStudio document is actually desirable. This is because some chunk options are ignored in the RStudio interface (e.g. dpi), and because the user certainly cares more about the knitted document that will be seen by others than the RStudio document that will never be seen by others.
Reacted by Greg, Wendell Challenger, MaxKman, Jan Broder Engler, Mike Jay, A. Solomon Kurz, Kenny Westerman, Charles Li, Christopher Ball, Frederik Aust and 7 more
@slowkow Thank you for reporting this, especially describing your experience in such detail. As you know, RStudio 1.3 is in early stages of development and is meant for testing purposes only, but thank you for trying it out and letting us know issues that you run into!
when passing fig.asp as in {r chunk_name, echo=TRUE, fig.asp = 1, fig.height=x, fig.width=y}, the issue was solved.
worked for me as well, after trying different values for fig.asp and fig.width
fig.asp: (NULL; numeric) The aspect ratio of the plot, i.e., the ratio of height/width. When fig.asp is specified, the height of a plot (the chunk option fig.height) is calculated from fig.width * fig.asp.
Note: this has statrted happening after I've started using .qmd. This does not happen when I use a .Rmd. Figure dimenstions remain the same from .Rmd --> HTML.
fig.width = 10, fig.height = 5
Left: HTML; right: inline in RStusio IDE in Windows (2022.12.0 Build 353)
I've spent hours trying to resize all of my graphs, thinking of switching back to .Rmd.
Revisiting this really quick. Everything works great and as expected when using inline chunk options like fig.width and fig.height, but RStudio fails to recognize the dimensions when using YAML-style chunk options:
@andrewheiss@netique is this issue still relevant then? From reviewing the history and linked issues it seems like this may have been solved by the fixes for #11708 (duplicated by #12305) and #12350/#12324
Activity
david-cortes commentedon Mar 27, 2019
The size of the plots in RStudio will also change if you resize the panel, if you click zoom, etc. How else would you expect it to work? you're not setting a pre-defined size in terms of pixels for your plot in there.
slowkow commentedon Mar 27, 2019
@david-cortes No, it does not change when I resize the panel. See the gif below.
slowkow commentedon Mar 27, 2019
RStudio ignores dpi, but respects fig.width and fig.height
It seems that RStudio ignores the
dpioption, but it respects thefig.widthandfig.heightoptions. This is not expected behavior.If RStudio respects
fig.widthandfig.height, then I also expect it to respectdpi.The two output devices are different
After trying a few more examples, I cannot get the output in the RStudio document to look the same as the output in the knitted document.
I guess the graphics devices and their settings are different for the two outputs. I would have expected them to be more similar.
This leaves the user in an undesirable situation:
The user cannot predict the appearance of the rendered output without knitting the document.
RStudio misleads the user to think the knitted document will look like the RStudio document. Then the user will be surprised when the output does not match what they saw while writing code and tweaking the chunk options.
Confusingly, the user must remember that a poor output in the RStudio document is actually desirable. This is because some chunk options are ignored in the RStudio interface (e.g. dpi), and because the user certainly cares more about the knitted document that will be seen by others than the RStudio document that will never be seen by others.
ronblum commentedon Mar 27, 2019
@slowkow Thank you for reporting this, especially describing your experience in such detail. As you know, RStudio 1.3 is in early stages of development and is meant for testing purposes only, but thank you for trying it out and letting us know issues that you run into!
ronblum commentedon Jun 7, 2019
See #4913 for a detailed example of the same behavior.
Note: this is the behavior in 1.1 and 1.2, so it's not new.
alyamahmoud commentedon Mar 22, 2020
when passing fig.asp as in {r chunk_name, echo=TRUE, fig.asp = 1, fig.height=x, fig.width=y}, the issue was solved.
charlesli37 commentedon Jan 4, 2021
worked for me as well, after trying different values for fig.asp and fig.width
source
mikebessuille commentedon Feb 12, 2021
Workaround seems good, so closing this.
51 remaining items
nikita-telkar commentedon Mar 20, 2023
Adding to this:
Note: this has statrted happening after I've started using
.qmd. This does not happen when I use a.Rmd. Figure dimenstions remain the same from.Rmd--> HTML.fig.width = 10, fig.height = 5I've spent hours trying to resize all of my graphs, thinking of switching back to
.Rmd.netique commentedon May 10, 2023
@nikita-telkar Have you tried any recent daily releases? I think this should be fixed even in the latest stable. Could you take a try?
andrewheiss commentedon Sep 26, 2023
Revisiting this really quick. Everything works great and as expected when using inline chunk options like
fig.widthandfig.height, but RStudio fails to recognize the dimensions when using YAML-style chunk options:netique commentedon Sep 27, 2023
@andrewheiss That's already tracked in #12305
jgutman commentedon Oct 16, 2023
@andrewheiss @netique is this issue still relevant then? From reviewing the history and linked issues it seems like this may have been solved by the fixes for #11708 (duplicated by #12305) and #12350/#12324
andrewheiss commentedon Oct 16, 2023
Oh cool, yeah, this issue isn't relevant—the resolution issues were fixed earlier, and #11708 addresses the YAML-style dimensions