R code to generate Fig.1