Modified the R code for plot2