working R scripts for plot1-4