9

On high DPI 4K monitors it seems that under Windows the RStudio plot window uses pixel doubling to make the plot legible (I'm using RStudio 0.99.483 and R 3.2.2 and Windows 8.1, but same result under Windows 10). This results in really fuzzy text & graphics (plus doesn't play well with Cleartype, as it results in colour fringing after pixel doubling).

Example:

qplot(Sepal.Length, Petal.Length, data = iris, color = Species, 
       size = Petal.Width, alpha = I(0.7))

with zoom in RStudio set to 200% gives me a fuzzy image (with colour fringing) like enter image description here

Zooming out completely in turn gives me a sharp image, but with far too small text, plot symbols & menu items: enter image description here

Could anybody perhaps recommend a solution to this problem? What web browser does RStudio use internally to display the plot window? Can anything be fixed on that front? At what level should this be fixed? RStudio or R itself (in grDevices or grid??). Just not really sure at what level this could be patched... Any thoughts?

EDIT: using

windows()
qplot(Sepal.Length, Petal.Length, data = iris, color = Species, 
       size = Petal.Width, alpha = I(0.7))

gives me a sharp image : enter image description here

but with the annoyance that the default window is then quite small (twice as small as on a normal monitor, 1/ 4 in terms of area), and that if I scale it, the size of the text will change relative to the rest (specifying width=XXX and height=XX has the same effect). So this comes back to the issue I always have with scaling R graphs. :-)

Using the additional options xpinch and ypinch in the windows call makes my window larger, e.g. :

windows(xpinch=340, ypinch=340)
qplot(Sepal.Length, Petal.Length, data = iris, color = Species, 
       size = Petal.Width, alpha = I(0.7))

enter image description here

but fonts don't seem to scale the way they should relative to the rest and plot symbols become slightly bigger (plot canvas though seems to have scaled OK, but not the line widths). Not sure where the problem is - whether the ggplot2 or grid output should adapt better to the xpinch and ypinch settings of the windows() device, or if it's something more low level. x11() doesn't seem to have any dpi settings, whereas quartz() does (argument dpi=...) - though I can't test the latter as I don't have a Mac... Guess part of the problem is that these different devices don't seem to have a consistent setting to specify the dpi, so maybe no surprise they are badly taken into account by particular packages... Not sure about the RStudio graphics device...

In short it seems pretty hard to make R graphs with good and reproducible scaling on different graphics devices with different dpi... Any thoughts, aside from exporting to PDF and viewing that?

Community
  • 1
  • 1
Tom Wenseleers
  • 7,535
  • 7
  • 63
  • 103
  • 1
    have you tried other devices (e.g. quartz/x11/window)? That would let you isolate whether it's an Rstudio issue (in which case it's probably best to discuss it with them directly). – baptiste Sep 08 '15 at 10:22
  • I just tried the windows() device as well, and that looks OK, except that it doesn't upscale at all (ie it just doesn't do any dpi scaling, and using arguments xpinch and ypinch messes up the scaling of the fonts) – Tom Wenseleers Sep 08 '15 at 14:23
  • ggplot2 tries hard to stick to absolute units (mm) for fonts, linewidths, etc. so it's not surprising that you can't resize them easily: it's fixed by design. What you need is a device/viewer that provides a post-drawing *zoom* independent of the graphics engine. pdf/svg are obvious solutions (because they won't look pixelated when zooming in), but there might be others to try, e.g. Acinonyx or Cairo for interactive use. – baptiste Sep 08 '15 at 19:38
  • Just had a try with CairoWin() and Acinonyx's idev() and alas no luck either... Real shame that zooming doesn't seem to be supported by any of these graphics engines... I'll have to stick with pdf, svg or ppt export then for now, no worries... And thanks again for the advice! Hopefully somebody will come up with a solution in the not too distant future! :-) – Tom Wenseleers Sep 08 '15 at 23:14
  • Rstudio seems to use [pdf.js](https://github.com/mozilla/pdf.js/) already as a pdf viewer for rmarkdown documents, so maybe it wouldn't be that hard to redirect the graphics pdf output to a new window, and trigger replotting whenever the window is resized (that's almost as "interactive" as it ever gets in standard R graphics) – baptiste Sep 08 '15 at 23:34
  • Yes something like that could be a very good idea! Or redirect SVG output to a browser window maybe... – Tom Wenseleers Sep 09 '15 at 00:27

2 Answers2

1

From what I know, higher DPI screens have problems with display scaling on many applications. Have you tried disabling the scaling? You can do it as follows:

  • Right click on the application's icon (R and Rstudio) and select Properties
  • Go to "Compatibility" tab and select the box that says "Disable display scaling on high DPI settings"
  • Click Apply and OK
  • Restart RStudio/R

I hope this can help your problem. Apologies if i understand the problem incorrectly or if you have tried this already.

P.s sorry I can only post an answer, not a comment. I dont have enough reputation yet

Tung Linh
  • 321
  • 1
  • 2
  • 16
  • Yes tried that already, but didn't help unfortunately! The easiest fix in my opinion to have R graphs render properly would be to always render them as PDFs and then use a decent PDF viewer, instead of this default plot window, which apparently uses an HTML/web viewer. – Tom Wenseleers Jun 30 '16 at 17:53
0

Maybe it's already obsolete, but I managed to solve it by turning off compatibility mode and turning on overriding high DPI scaling behavior to System (Enhanced)

Brooky
  • 31
  • 5