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.
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.