← Back to R Course | Chapter 10: Data Visualization | Lesson 5 of 7

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:

  1. pie()
Syntax
r
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()

markup
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")
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
  1. Using a pie chart with many slices or similar values, which is hard to read and a bar chart is clearer.
  2. Passing percentages that do not add to 100 and expecting a full circle, when pie() scales to the total anyway.
  3. Forgetting labels when 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.