Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R / RStudio : graph scaling issues & fuzziness on high dpi screens

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?

like image 809
Tom Wenseleers Avatar asked Sep 05 '15 08:09

Tom Wenseleers


1 Answers

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

like image 110
Tung Linh Avatar answered Sep 21 '22 09:09

Tung Linh