Adding code and plot for plot4