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 36the output of the barplot() function and then call text() with postions <strong>for</strong> the x and ycoordinates; an argument, labels=, <strong>for</strong> the text; and the argument pos=1 to put the textjust below the bar. This example (not shown) illustrates the process:> our.data = c(1,2,2.5); names(our.data)=1:4> bp = barplot(our.data)> text(bp, our.data, labels = our.data, pos = 1)The x-coordinates are returned by barplot(); the y-coordinates of the text are the heightsof the bars given by the values in the data vector.2.1.3 Pie chartsThe pie chart graphic is used to display the relative frequencies or proportions of thelevels of a categorical variable. The pie chart represents these as wedges of a circle or pie.Pie charts, like barplots, are widely found in the media. However, unlike barplots, piecharts have lost favor among statisticians, as they don’t really do well what they aim todo.Creating a pie chart is more or less the same as creating a barplot, except that we usethe pie() function. Similar arguments are used to add names or change the colors.For example, to produce a pie chart <strong>for</strong> the sales data in Example 2.3, we use thefollowing commands (Figure 2.4):> sales<strong>John</strong> Jack Suzy45 44 46> pie(sales, main="sales")The argument main= is used to set a main title. Alternatively, the title () function can beused to add a title to a figure. Again, the names attribute of sales is used to label the piechart. Alternatively, the labels= argument is available. For the graphic in the text,col=gray (c (, 7, .85, .95)) was used to change the colors.Figure 2.4 An example of a piechart. Can the sales leader beidentified?

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

Saved successfully!

Ooh no, something went wrong!