R code for plot 1,2,3,4