revised r file for figure 1