R code and corresponding plot 1