.R file for Plot 3