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.

<strong>Using</strong> R <strong>for</strong> introductory statistics 58Figure 2.12 Histogram of on-basepercentage <strong>for</strong> the 2002 MLB seasonAdding a title to a histogram or other graphic The hist() function adds a default title toa histogram. This can be changed with the main=argument. This argument is common tomany of the plotting functions we will encounter. For example, this command produces ahistogram with a custom title:> hist(OBP, main="My histogram of the OBP dataset")Setting main= to an empty string or NULL will print no title. In this case, one can beadded at a later point with the title() function. In addition, this function can be used tolabel the x- and y-axes with the arguments xlab= and ylab=.Density estimates and frequency polygonsIn many statistics books, a frequency polygon is presented in addition to a histogram.Figure 2.13 displays such a frequency polygon <strong>for</strong> the waiting variable. To draw afrequency polygon, we select the bins (all the same size) and find the frequencies, as wewould <strong>for</strong> the histogram. Rather than draw a bar, though, we draw a point at the midpointof the bin with height given by the frequency, then connect these points with straightlines to <strong>for</strong>m a polygon.Creating a frequency polygon The commands to create the frequency polygon inFigure 2.13 are:> bins = seq(42, 109, by=10)> freqs y.pts = c(0, freqs, 0)> x.pts = seq(37,107,by=10)> plot(x.pts,y.pts,type="l") # connect points withlines> rug(waiting) # show values

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

Saved successfully!

Ooh no, something went wrong!