R code to generate the 4 plots