R code and resulting plots