code to generate figure 2