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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Using</strong> R <strong>for</strong> introductory statistics 64Figure 2.18 Boxplot of all-time grossmovie revenues in United StatesMaking boxplots in R Boxplots are drawn in R with the boxplot () function. Figure 2.18was made with these commands:> attach(alltime.movies)> boxplot(Gross,ylab="All-time gross sales")> f= fivemun(Gross)> text(rep(1.3,5),f,labels=c("minimum","lower hinge",+ "median","upper hinge","maximum"))The text() function places the values of labels=on the graphic as specified. Commonarguments <strong>for</strong> boxplot() are col= to set a color <strong>for</strong> the box, horizontal=TRUE to changethe orientation of the boxplot, and notch=TRUE to add a notch to the waist of the boxwhere the median is marked.Getting the outliers If we are curious as to what the top five movies are that aremarked separately, we can use the fivemim() function to find out. (First we get the namesusing the rownames() function.)> f = fivenum(Gross)> the.names = rownames(alltime.movies)> the.names[Gross > f[4] + 1.5*(f[4]-f[2])][1] “Titanic "[2] “Star Wars "[3] “E.T. "[4] “Star Wars: The Phantom Menace "[5] “Spider-Man "> detach(alltime.movies) # tidy upAlternately, this in<strong>for</strong>mation is available in the (invisible) output of the boxplot() functionin the list element named “out”.

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

Saved successfully!

Ooh no, something went wrong!