R Code for Plot2