R Code for Plot 2