Skip to content

Instantly share code, notes, and snippets.

@taniki
Last active December 14, 2015 18:59
Show Gist options
  • Select an option

  • Save taniki/5133358 to your computer and use it in GitHub Desktop.

Select an option

Save taniki/5133358 to your computer and use it in GitHub Desktop.
how to get anti-alias with R (and knitr) under ubuntu

I had to switch to a personal ubuntu PC lately. I already tried to get anti-alias in R outputs on my ubuntu workstation but failed and relied on an imac to get pixel perfect plot (ggplot2 <3). The latter one use QUARTZ by default and I tried to install quickly Cairo but it was not very simple and did not got time to fix it. Now that I have to, I did it. It is a minor problem and I am sure it will help other ubuntu R users (:

The problem is that :

  • install.packages("Cairo") outputs dependencie errors without telling explicitly how to fix them (particulary libxt)
  • apt-get install r-cran-cairo does install something but it does not appear in R and does not fetch dependencies either

Then in the terminal, you will first need to :

$ sudo apt-get install libcairo2 libcairo2-dev libxt-dev

Then in the R console :

install.packages('Cairo')

If you are using knitr directly or with R Studio, you will need to add an extra code at the beginning of your notebooks.

```{r global_setup, echo=FALSE, warning=FALSE, cache=FALSE}
opts_chunk$set(dev="CairoPNG")
```
@yihui

yihui commented Mar 11, 2013

Copy link
Copy Markdown

normally cairo comes by default in png(); did you install R by apt-get install r-base? (http://cran.r-project.org/bin/linux/ubuntu/)

@taniki

taniki commented Mar 13, 2013

Copy link
Copy Markdown
Author

yep I used apt-get on two different machines and none of them produced anti-aliased plots before I set it with opts_chunk$set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment