the R code with plot