R code to construct the plot