10.07.2015 Views

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Appendix D 366Figure D.3 Per-capita GDP versusemissions by countryold par () settings are saved. As these will be changed during the function, it's nice toreturn them as we found them. Then the layout of the graph is specified with the layout ()function.Then the histograms are drawn. Care is taken to get a similar number of breaks and asimilar size. As well, the line par (mar=c (0, 3, 1, 1)) sets up the margins so that not toomuch white space appears.Finally, the scatterplot is drawn. The expression deparse (substitute (x)) finds thename of the variable that we called the function with <strong>for</strong> the label. We use switch() to addone of several trend lines: the regression line given by 1m(), the fit given by lowess (),and the Friedman super-smoother fit given by supsmu() from the stats package. Thislogic could have been implemented with if-then-else lines, but that approach is morecluttered. The invisible () function is used to return quietly.This function could be improved by adding an interface to the model <strong>for</strong>mula notation.The techniques to do that are discussed in Appendix E.scatter.with.hist

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!