R code for creating plot2