R code to generate Figure.2
Figure 2 as asked