Implement R script for generating plots