Tidied up the code
R code to create plot 3
R code to create plot 4