reformated R code for plot1