Learn R Programming  /  Base Graphics  /  Pie Chart

Pie Chart

pie() draws proportional slices from a set of values. It is easy to make, but you should know its limitations before reaching for it.

A Basic Pie Chart

R Code
shares <- c(40, 25, 20, 15)
labels <- c("Product A", "Product B", "Product C", "Product D")

pie(shares, labels = labels, main = "Market Share",
    col = c("steelblue","tomato","gold","lightgreen"))

Adding Percentage Labels

R Code
pct <- round(shares / sum(shares) * 100, 1)
labels_pct <- paste0(labels, " (", pct, "%)")

pie(shares, labels = labels_pct, main = "Market Share with Percentages")

Why Statisticians Often Avoid Pie Charts

⚠ Common Mistake
The human eye is much better at comparing the LENGTH of bars than the ANGLE of pie slices. Once you have more than 3-4 categories, or slices with similar sizes, a pie chart becomes genuinely harder to read accurately than the equivalent bar chart.
R Code
# same data, shown as a bar chart for comparison
barplot(shares, names.arg = labels, col = "steelblue",
        main = "Market Share (Bar Chart)", ylab = "Share (%)")

Key Points

  • pie(values, labels = ...) draws proportional slices from a numeric vector.
  • Compute percentages manually with round(x / sum(x) * 100, 1) and paste0() to label slices clearly.
  • For more than a few categories, prefer a bar chart - it is easier to compare accurately.