Update R Code for plot 4