mhovd
mhovd

Reputation: 4067

Improving quality of RStudio graphics device (preview)

When using RStudio, plots may be examined in the "Plots" pane or the built-in Viewer. However, I noticed that the quality of these previews is worse when compared to a saved plot. Obviously it is possible to export or save the image, with no lack of methods (pdf(), png(), ggsave(), etc).

Using iris as an example, the following screenshot produces the following plot

library(tidyverse)
p.iris = iris %>% 
  ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE)

p.iris

Screenshot of Rstudio plot preview

Compared to the saved version of the same plot, with a high DPI.

ggsave(plot = p.iris, filename = "Example.png", dpi = 320)

While the difference is subtle, e.g. the line from geom_smooth is clearer. Saved version of the same plot

If inspecting the plot preview, you can see that the plot is saved to a .png

<img id="img" width="100%" height="100%" style="display: inline;" 
src="http://127.0.0.1:35473/graphics/c3c6aa95-f458-477e-af54-f443f93ad673.png">

Suppose I don't mind additional resources or time being used to render a better quality preview - which settings would I adjust?

Upvotes: 3

Views: 2174

Answers (1)

TimTeaFan
TimTeaFan

Reputation: 18551

You could install RStudio >= v1.4 and the package {ragg} and then set the graphic device backend to AGG as described here.

enter image description here

This should make the preview quality better.

Note that this problem is platform dependent. I have the same poor quality of previews on my windows machine, while I have no such problems (even without {ragg}) on my mac.

Upvotes: 7

Related Questions