.R file for Plot 4