added R code and output plots