Pie Chart

A pie chart (or a circle graph) is a circular chart divided into sectors, illustrating proportion. In a pie chart, the arc length of each sector (and consequently its central angle and area), is proportional to the quantity it represents. It is useful in comparing a slice with the whole pie but not effective to compare slices because our eyes are good at judging linear measures and bad at judging relative areas.

To generate a pie chart, the function pie() can be used. The function takes a vector of data. The most useful options include:

  • labels: label the slices
  • col: colors of the slices
  • main: title of the plot

As an example, we compare the proportions of male and female participants in the ACTIVE study. The plot clearly showed there were more female participants than male participants in the sample. Note that the function table() calculates the number of male and female participants in the variable sex of the data set active. One can also "attach" the data and use the variable sex directly.

> usedata('active') > head(active) site age edu group booster sex reason ufov hvltt hvltt2 hvltt3 hvltt4 mmse id 1 1 76 12 1 1 1 28 16 28 28 17 22 27 1 2 1 67 10 1 1 2 13 20 24 22 20 27 25 2 3 6 67 13 3 1 2 24 16 24 24 28 27 27 3 4 5 72 16 1 1 2 33 16 35 34 32 34 30 4 5 4 69 12 4 0 2 30 16 35 29 34 34 28 5 6 1 70 13 1 1 1 35 23 29 27 26 29 23 6 > pie(table(active$sex), labels=c('Male','Female'), col=c('red','blue'), main='Pie chart') >

To cite the book, use: Zhang, Z. & Wang, L. (2017-2022). Advanced statistics using R. Granger, IN: ISDSA Press. https://doi.org/10.35566/advstats. ISBN: 978-1-946728-01-2.
To take the full advantage of the book such as running analysis within your web browser, please subscribe.