Chapter 39: R Pie Charts
R Pie Charts — one of the most debated and emotionally charged plot types in the entire data visualization world.
I’m going to explain this topic very honestly and in detail — like your real offline teacher who wants you to understand why pie charts are controversial, when they are actually useful, and how to make them properly (and tastefully) in R when you really need them.
1. What is a Pie Chart? (Simple & Honest Definition)
A pie chart is a circular statistical graphic divided into slices (sectors) to illustrate numerical proportion.
- Each slice = one category
- Size of slice = proportion / percentage of the whole
- The full circle = 100% (or the total sum)
Classic examples:
- Market share of smartphone brands (Apple 45%, Samsung 30%, Others 25%)
- Budget allocation (Rent 40%, Food 25%, Savings 20%, Fun 15%)
- Election vote share (Party A 38%, Party B 32%, …)
2. The Great Pie Chart Controversy (You Should Know This)
Pie charts are very polarizing in the data visualization community — especially since ~2010–2025.
Arguments against pie charts (very common opinion in 2026):
- Humans are bad at comparing areas / angles (especially when slices are similar in size)
- Hard to read precise values (is that slice 22% or 27%?)
- Too many slices (>5–6) → looks like a rainbow mess
- Labels get crowded, overlapping, hard to read
- Bar charts or stacked bars usually do the job much better and are easier to compare
Arguments for pie charts (when they are acceptable):
- When there are very few categories (2–5 max)
- When one category is obviously dominant (e.g., 75% vs 10% vs 15%)
- When the story is “part-to-whole” and you want to show composition visually
- When the audience expects a pie chart (common in business reports, newspapers, non-technical presentations)
- Donated organ usage, election results with 3 candidates, simple budget pies — these still look nice
2026 community consensus (most data scientists / statisticians / visualization experts):
Use pie charts sparingly and only when they are the clearest way to communicate the message. Prefer bar charts (horizontal or vertical), donut charts, treemaps, or waffle charts in almost all other cases.
3. How to Make Pie Charts in R (Two Main Ways)
A. Base R – pie() function (simple but limited)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# Simple example – Hyderabad favorite foods survey (fake data) foods <- c("Biryani" = 45, "Haleem" = 25, "Irani Chai" = 15, "Paya" = 10, "Other" = 5) pie(foods, main = "Favorite Foods in Hyderabad – 2026 Survey", col = c("#FF6F61", "#6B7280", "#FBBF24", "#34D399", "#A78BFA"), labels = paste(names(foods), foods, "%"), clockwise = TRUE, init.angle = -90) # starts at top # Add legend if labels are too crowded legend("topright", names(foods), fill = c("#FF6F61","#6B7280","#FBBF24","#34D399","#A78BFA"), bty = "n", cex = 0.9) |
B. ggplot2 – Much more modern & customizable (strongly recommended)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
library(ggplot2) library(dplyr) # Same data in data frame (ggplot2 prefers this format) food_df <- data.frame( food = c("Biryani", "Haleem", "Irani Chai", "Paya", "Other"), percent = c(45, 25, 15, 10, 5) ) |> mutate( food = factor(food, levels = food), # keep order label_pos = cumsum(percent) - percent/2 # position for labels ) ggplot(food_df, aes(x = "", y = percent, fill = food)) + geom_col(width = 1, color = "white") + # makes the pie coord_polar("y", start = 0) + # turns bar into pie geom_text(aes(label = paste(food, percent, "%"), y = label_pos), color = "white", size = 4.5, fontface = "bold") + scale_fill_brewer(palette = "Set2") + labs( title = "Favorite Foods in Hyderabad – 2026 Survey", fill = "Food Item" ) + theme_void() + # removes all background/axes theme(legend.position = "right", plot.title = element_text(hjust = 0.5, face = "bold", size = 16)) |
→ This is a donut-style pie (because we used geom_col + coord_polar). Pure pie would have x = 1 instead of “”, but donut is generally preferred (less visual clutter in the center).
4. Best Practices When You Must Use a Pie Chart (2026 Style)
- Maximum 5–6 slices (ideally 3–4)
- Order slices from largest to smallest (or meaningful order)
- Use meaningful colors — avoid rainbow unless categories are unrelated
- Put percentage labels directly on slices (not in legend)
- Consider donut chart — easier to read labels in center
- Add title + source/note
- Avoid 3D pies — they distort perception even more
- If comparing many categories → use bar chart or lollipop instead
5. Quick Alternatives That Are Usually Better
- Horizontal bar chart (easiest to read labels & compare sizes)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 |
ggplot(food_df, aes(x = reorder(food, percent), y = percent, fill = food)) + geom_col() + geom_text(aes(label = paste(percent, "%")), hjust = -0.2, size = 4) + coord_flip() + scale_fill_brewer(palette = "Set2") + theme_minimal() + labs(title = "Favorite Foods – Horizontal Bar (Usually Better Than Pie)") |
- Waffle chart (very popular in 2025–2026 for part-to-whole)
(You can use waffle or ggwaffle packages)
Your Mini Practice Right Now
Copy this ggplot2 block — then try:
- Change to 3 categories only (remove small slices)
- Use coord_polar() without hole (classic pie)
- Try theme(legend.position = “none”) and rely only on labels
- Change palette to “Pastel1” or “Spectral”
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
library(ggplot2) data <- data.frame( category = c("Rent", "Food", "Transport", "Entertainment", "Savings"), share = c(40, 25, 15, 10, 10) ) ggplot(data, aes(x = "", y = share, fill = category)) + geom_col(width = 0.9, color = "white") + coord_polar("y", start = 0) + geom_text(aes(label = paste(category, share, "%"), y = cumsum(share) - share/2), color = "black", size = 4.5) + scale_fill_brewer(palette = "Pastel1") + labs(title = "Monthly Budget Allocation – Sample") + theme_void() + theme(legend.position = "bottom") |
Now compare it visually with this bar version:
|
0 1 2 3 4 5 6 7 8 9 10 11 |
ggplot(data, aes(x = reorder(category, share), y = share, fill = category)) + geom_col() + geom_text(aes(label = paste(share, "%")), vjust = -0.5) + scale_fill_brewer(palette = "Pastel1") + theme_minimal() + labs(title = "Same Data – Bar Chart (Usually Easier to Compare)") |
Which one do you find easier to read quickly?
Final Teacher Advice
Pie charts are not evil — they are just overused and misused. Use them only when:
- 2–5 categories
- Part-to-whole story is the main message
- One slice is clearly dominant
- Audience expects / likes pies (common in business / media)
Otherwise → bar chart wins 9 out of 10 times in clarity and accuracy.
Want to go deeper?
- Make donut charts with hole in center
- Add percentages with % sign nicely formatted
- Combine pie + bar (hybrid viz)
- Or next plot type (histogram, boxplot, heatmap)?
Just tell me — whiteboard is ready! 📊🥧🚀
