R script to produce plot 4