Getting smoothed graphs with R on Ubuntu

I updated my system and reinstalled R, and now my standard X-11 graphics are not smoothed - they look jagged and the font looks bad.

It seems that I recall such a problem in the past, but I do not remember what I did with it.

Additional Information:

  • qplot also comes out without smoothing
  • plotting for a png device also produces unbalanced output
  • plotting for a pdf device, however, creates a nice smoothing look.

One more thing: I am now launching this version of R / Ubuntu, a couple of months or so. I do not know if this build problem immediately occurred with a new R installation, or if I did something after that to break it. I don’t remember the absence of anti-aliasing being noticed before, but I probably didn’t pay attention and did not make much conspiracy.

Does anyone know what a fix is? I am currently running R 3.2.1, compiled from source, with Ubuntu 14.04.3 LTS.

A few more things. After discussing here, I tried to install Cairo, but it failed. In addition, I managed to get non-smoothed graphics in R / linux without installing Cairo in the past, and I would prefer not to install additional things if it is not necessary.

Here is my X11.options() :

 $display [1] "" $width [1] NA $height [1] NA $pointsize [1] 12 $bg [1] "transparent" $canvas [1] "white" $gamma [1] 1 $colortype [1] "true" $maxcubesize [1] 256 $fonts [1] "-adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*" [2] "-adobe-symbol-medium-r-*-*-%d-*-*-*-*-*-*-*" $family [1] "sans" $xpos [1] NA $ypos [1] NA $title [1] "" $type [1] "Xlib" $antialias [1] "default" 
+6
source share
1 answer

I run R 3.4.0, and by default for X11() and png() devices, I get smooth lines, “dots” and graph axes.

However, there are certain Microsoft fonts packages that must be installed on my system in order to get smoothed text. I can not speak for Ubuntu, but in Arch Linux the package names were "ttf-ms-fonts" and "fontconfig-ttf-ms-fonts", as in AUR. A good Google search should include similar packages for your own system.

Here are some graphs created by the png() device with "ttf-ms-fonts" installed and installed.

  • Without "ttf-ms-fonts":

brownian-motion-no-msfonts

  • With "ttf-ms-fonts":

brownian-motion-with-msfonts

I hope that you can see that the lines and circles in both sections are smoothed, but only the second graph has a smoothed text.

Here is the code I used to create the above graphs:

 set.seed(1); brownian=cumsum(runif(1e3,min=-1)); png("brownian-no-msfonts.png",height=400); par(cex=1.3); plot(brownian,ylim=c(-10,15), ylab="Position",xlab="Time",main="Brownian Motion"); lines(brownian+7); dev.off() 

I confirmed that I need both "ttf-ms-fonts" and "fontconfig-ttf-ms-fonts" (the latter, I think, sets up some fonts to be used by default) to get anti-aliasing of the text in R, although it requires only the first package, for example, get smoothed text in Firefox.

However, I played with the “knitr” package, and I noticed that if I compile my documents using the “rendering” from the “rmarkdown” package, then it can create smoothed graphics with or without “ttf” -ms-fonts. I don’t figured out how this is done I know that he runs Pandoc, which creates HTML with embedded fonts, but I'm not sure if the rmarkdown package itself includes fonts, or if it just knows better where to find good ones on my system .

I feel superficial to spend time on this, but whatever.

+2
source

All Articles