Repository navigation
Closed
Description
I originally reported the problem in RMarkdown project 4521 and this might be issue related to 1827
System details
RStudio Edition : Desktop
RStudio Version : 1.3.959
OS Version : macOS 10.14.6
R Version : 3.6.1
Steps to reproduce the problem
- In R Markdown document create a plot that has many labels
- Move R Studio window to different monitor
- Slightly resize R Studio window
- Rerun plot code
Describe the problem in detail
RStudio renders figures inconsistently depending on which monitor is the code executed. When I run code chunk on retina display the text in the figure is rendered smaller, but when I move the window to my second 2K display (ThinkVision 23.8'' P24H-10 QHD) all the labels and margins are rendered way larger, which dramatically change how the figure looks like.
Here is a sample code (cowplot package is to exaggerate the issue, but it behaves the same when cowplot is deactivated)
{r message=FALSE, warning=FALSE, fig.width = 8, fig.height = 6}
library(tidyverse)
library(cowplot)
data <- data.frame(x = rnorm(999), y = rep(c("a", "b", "c")))
p1 <- p2 <- data %>% ggplot() +
geom_histogram(aes(x = x, fill = y)) +
facet_wrap(vars(y)) +
scale_x_log10() +
labs(title = "Test subtitile")
plot_grid(p1, p1, labels = c("A", "B"), ncol = 1, label_size = 20) +
draw_plot_label("Test main titile", size = 25, x = 0.5, y = 1.015, hjust = 0.5, vjust = 0.5) +
theme(plot.margin = unit(c(1.5,0,0,0), "cm"))
Output 1:1 screenshots:
- I have read the guide to submitting good bug reports at https://github.com/rstudio/rstudio/wiki/Writing-Good-Bug-Reports .
- I have installed the latest version of RStudio and confirmed that the issue still persists.
- If I am reporting a RStudio crash, I have included a diagnostics report. https://support.rstudio.com/hc/en-us/articles/200321257-Running-a-Diagnostics-Report
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
Reacted by Greg and Larisa Stoltzfus

Activity
stale commentedon Feb 5, 2021
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions.
stale commentedon Feb 19, 2021
This issue has been automatically closed due to inactivity.
EoinTravers commentedon Mar 9, 2021
I have the same issue.
I can add the following:
This isn't restricted to ggplot
Retina display:
External display:
HTML Output Matches External Display
When the document is knit to html, using the default options, the generated images are small, the same as those seen on the external display.
fig.retinaKniting with default settings, the knitr
fig.retinaparameter is set to 2.Changing this in the yaml
is registered...
...but doesn't change the size of the output figures, suggesting the issue might be somewhere in the knitr or rmarkdown packages.
Changing the setting for a specific chunk also has no effect on the output.
System Info
cderv commentedon Jan 10, 2022
I don't know if there is an issue with RStudio or not. Regarding last comment, I answered here rstudio/rmarkdown#1827 (comment) on how
fig.retinaplays out to me.EoinTravers commentedon Jan 12, 2022
This discussion on twitter is relevant to this issue, and includes this nice but hacky fix.
Mashin6 commentedon Jan 12, 2022
Referencing related issues #2098 and #7892. (thanks @cderv for looking those up)
cderv commentedon Jan 12, 2022
@ronblum would it be possible to reopen this issue closed by stale bot ? Seems still an issue and related to a few others about resolution of figure in Notebook . Thanks!
jeffvroom commentedon Feb 21, 2022
I see a few problems that mostly center around [this code] (
rstudio/src/cpp/session/modules/NotebookPlots.R
Lines 27 to 30 in 2c92cd9
fig.retinaif it's being set in the annotations but instead always usesdevicePixelRatiothat comes from the IDE that gets it from the browser'swindow.devicePixelRatio. Here is where we get fig.width/height but do not get fig.retina to override the devicePixelRatio.resand that doubles the effect. So in my test, with fig.width/fig.height = 2", the resulting resolution is 768 that would be 4" on a display with 96 dpi.In at least one customer situation, it seems like we need a way to disable the effect of the retina, or to at least not double it up because the results of ggplot are not consistent with other graphics they are rendering.
2 remaining items
ronblum commentedon Dec 2, 2022
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.
jonvanausdeln commentedon Feb 6, 2023
I tried on latest daily, 2023.03.0-daily+280. However, I would like confirmation from @Mashin6 and/or @EoinTravers that this solves their issue.
Mashin6 commentedon Feb 7, 2023
I played a bit with the latest
2023.03.0-daily+293and for me the main issue seems to be gone. Figures are rendered with the same proportion of text size, spacings, etc.However I noticed that at different screen resolutions/scalings the figures are rendered at different pixel dimensions. My suspicion is that the problem is somehow related to non-HiDPI resolutions/monitors.
retina display - all resolutions - figure dimensions 768 × 768 pixels

External Monitor - 2560x1140 (native) - figure dimensions 384 × 384 pixels

External Monitor - 1280x720 (HiDPI scale) - figure dimensions 768 × 768 pixels

jonvanausdeln commentedon Feb 7, 2023
Thank you @Mashin6! Since the main issue is resolved, I will close out this issue. Would you be able to open a new issue on what you are still experiencing? I would be happy to open if you'd like, I just don't want to miss any details.
frederikziebell commentedon Jun 6, 2024
@jeffvroom Is there a way to set the device pixel ratio from a current RStudio session, similar to the
.Callyou described above to view it?kevinushey commentedon Jun 6, 2024
@frederikziebell I suspect not, but you might want to file a separate issue to make sure your request isn't lost.