Anti-aliasing in Windows R

Keren Xu

2019/11/17

If you are using Windows R, you must have noticed that it generates pixelated graphs. The anti-alias option is unfortunately a default only in OSX or Linux.

ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, color=Species, shape=Species)) + 
  geom_point()+
  geom_smooth(method=lm, se=FALSE) + 
  theme_classic()

Let’s zoom in a little bit:

ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, color=Species, shape=Species)) + 
  geom_point()+
  geom_smooth(method=lm, se=FALSE) + 
  theme_classic() + 
  coord_cartesian(ylim = c(5.45, 5.6), xlim = c(2.25, 2.4))

Let’s load the package Cairo, and use ```{r, dev = 'CairoPNG'} We now get the anti-aliasing plot!

library(Cairo)
ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, color=Species, shape=Species)) + 
  geom_point()+ 
  geom_smooth(method=lm, se=FALSE) + theme_classic()

Let’s also zoom in a little bit:

ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, color=Species, shape=Species)) + 
  geom_point()+
  geom_smooth(method=lm, se=FALSE) + 
  theme_classic() + 
  coord_cartesian(ylim = c(5.45, 5.6), xlim = c(2.25, 2.4))