reformated R code for plot4.R