corrected R script for plot 4