R code and plots