pie()
A pie chart is a circle cut into slices, where a bigger slice means a bigger share. It is like splitting a pizza to show who got how much.
In this page:
Syntax
pie(values, labels = labels, main = "title")
pie()
pie(values) draws a pie chart from a vector of values, showing each as a proportional slice of the whole.
Pie charts are best used sparingly and only for a small number of categories, since comparing slice angles is harder for viewers than comparing bar heights. labels sets the text shown next to each slice.
Note:
For more than a handful of categories, prefer barplot() over pie() -- proportions are much easier to compare as bar heights.
Example: pie()
shares <- c(Product_A = 40, Product_B = 35, Product_C = 25)
print(shares)
cat("pie(shares) would draw a pie chart with these three proportional slices\n")
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
Common Mistakes
- Using a pie chart with many slices or similar values, which is hard to read and a bar chart is clearer.
- Passing percentages that do not add to 100 and expecting a full circle, when
pie()scales to the total anyway. - Forgetting
labelswhen the vector has no names, so slices are not labeled.
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: