R code for fig2