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 76Figure 3.2 Left graphic shows sideby-sideboxplots of placebo andephedra group. Right graphiccontains densityplots of the twovariables.3.2.2 DensityplotsWe can compare distributions with two histograms, but it is difficult to put both on thesame graphic. Densityplots, however, lend themselves readily to this. *We draw the first densityplot with the plot() function and add subsequent ones withthe lines () function. The argument lty=can be set to a value between 1 and 6, to changethe type of line drawn <strong>for</strong> identification purposes. For example, the densityplots in Figure3.2 are made as follows:* You can compare histograms by recording the graphs. In the Windows GUI, you can turn onrecording from the menu bar of the graph window. In general, you can store the current plot in avariable with recordPlot(), and view this stored plot with replayPlot().> plot(density(pi),ylim=c(0,0.07), main="densityplotsof ep and pi")> lines(density(ep), lty=2)The argument ylim=adjusts the y-axis to accommodate both densities. The value wasarrived at after we plotted both densities and found the maximum values.3.2.3 Strip chartsStrip charts can compare distributions effectively when the values are similar and therearen’t too many. To create a strip chart with multiple data vectors, we first combine thedata vectors into a list with the list() function. By using a named list the stripchart will bedrawn with labels <strong>for</strong> the data sets.

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

Saved successfully!

Ooh no, something went wrong!