R code for producing plot2