To install R packages without root access:

Create a file .Renviron in our home folder with the line

R_LIBS_USER=~/Rpackages/

You may have to create the folder under your home directory:
mkdir ~/Rpackages

Whenever you start R, the directory ~/Rpackages/ is added to the list of places to look for R packages and we can simply install new ones through the R command line:

> install.packages("ggplot2")
> library(ggplot2)

should install it in the custom directory. You can use the “work” location to share these with your group (substituting your group name),

R_LIBS_USER=/scratch/groups/group-name/Rpackages/

If you use different versions of R for different purposes, you can add to the library folder a %V which R will substitute with the version number.

Adapted from
http://www.r-bloggers.com/installing-r-packages/

Relevant R documentation
https://stat.ethz.ch/R-manual/R-devel/library/base/html/libPaths.html