Modified the R code for plot3