Converted the plot in plot1.R to a function