R code for creating plot4