The The R Primer logo Primer

Draw a pie chart

You want to draw a pie chart

Solution: It is generally recommended to avoid presenting data as pie charts (see the book by Tufte for arguments why most pie charts are a bad idea).

The pie function in R can be used to generate pie charts. Its first argument should be a vector of values that are used to define the relative size of the individual slices of the pie. Additional arguments are col, and label which are vectors that set the colors and labels of the individual slices, respectively. Normally, the first cut of the first slice is along the x-axis, but we can change that with the init.angle argument as shown below.

> pie(c(20, 80), init.angle=-40, 
+     col=c("black", "yellow"), 
+     label=c("Does not\nresemble\nPac-man", "Resembles Pac-man"))

The R code produces the pie plot shown below.

Back to tips.