Setting up Linux

An easy way of running some linux distribution on android is using GNURoot with the wheezy distro. Make sure to launch the rootfs as fake root.

GNURoot allows access to special keys via the volume up/volume down buttons of your phone and some character on the virtual keyboard:

  • ctrl+c: volume down+c
  • escape: volume up+e
  • tab: volume up+t
  • arrow keys: volume up+w/a/s/d.

Installing R

In order to make adding repositories easier via the add-apt-repository command, execute the following

$ apt-get install python-software-properties

Then add a repository which hosts the wanted R package (e.g. the ‘rstudio’ one)

$ add-apt-repository "deb wheezy-cran3/"
$ apt-key adv --keyserver --recv-keys 381BA480
$ apt-get update

Finally, install R itself

$ apt-get install r-base r-base-dev

Plotting in the Terminal

Plots to stdout can be done by using the txtplot package

> install.packages("txtplot", dependencies=TRUE)
> txtboxplot(rnorm(100, 1, 2), rnorm(50, 2, 5))

Proper plots with ggplot2

It is of course possible to simply use ggsave in order to save your plots. However, in order to have a more elaborate preview, follow the next few steps.

In order to get proper plots with ggplot2 you have to set up an X server first. This can be done by installing an android app like e.g. XServer XSDL and launching your favourite window manager into it.

Firstly start the X server, secondly your linux distro. Then introduce the two and start some window manager:

$ apt-get install i3
$ export DISPLAY=
$ i3 &

In R, you can then use ggplot2 as you normally would.

> install.packages("ggplot2", dependencies=TRUE)
> p <- qplot(gear, mpg, data=mtcars)

In order to see the resulting plot, switch to the X server and admire the view!