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 DMore on graphics with RThis appendix revisits many of the plotting techniques presented in the text offering moredetail and organization. In addition, functions are provided <strong>for</strong> two new graphics: asquareplot and an enhanced scatterplot.This appendix provides a good deal of extra in<strong>for</strong>mation but is by no means inclusive.More facts are available in the manual An Introduction to R that accompanies R, and inthe help pages ?plot and ?par. The organization of this appendix was inspired by someexcellent notes by R pioneer Ross Ihaka, which were found athttp://www.stat.auckland.ac.nz/ ~ ihaka/120/.D.1 Low- and high-level graphic functionsConsider what the command plot (x, y) does when making a scatterplot. First it sets up aplot device if one isn’t already present. Then areas <strong>for</strong> the figure and the margins areassigned, the limits on the x- and y-axes are calculated, the axes are drawn and labeled, abox is drawn around the graphic, and, finally, the points are plotted.If we issue the command plot (x,y,type="n") instead of the command plot (x, y), allbut the last step of plotting the points is done. We refer to this as setting up the plotfigure. High-level graphic functions will do this; low-level graphic functions add to theexisting figure. The plot() function allows <strong>for</strong> many arguments to adjust this process. Forexample, we can plot connected line segments instead of points; we can add colors,labels, and titles; and we can adjust the axes. More details are in the help page ?plot.What we focus on next is how to set up a figure step-by-step so that we can gain fullcontrol over the details. This is useful when we are designing our own graphics, or whenwe are not satisfied with the defaults.D.1.1 Setting up a plot figureThe following steps are <strong>for</strong> the creation of any graphic, not just a scatterplot.A plot deviceA graphic is drawn to a plot device. Generally speaking, a default plot device is used. Ifwe want, though, we can create a new device that allows us to control the type of deviceand the size of the figure. How we do so varies according to our system and ourintentions. In Windows, the function windows () will create a device; on a UNIXmachine running X Windows, the function X11 () will create a device; and on Mac OS X,the function quartz () will make a new device using the default windowing system. Thearguments width= and height= set the size of the graphic figure. An argument point size=

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

Saved successfully!

Ooh no, something went wrong!