R Code for Plot 3