Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
A ggplot piechart is not a dedicated geom. In ggplot2 you draw a single stacked bar and then bend it into a circle with coord_polar(theta = "y"). The ggplot2 reference states it directly: “The polar coordinate system is most commonly used for pie charts, which are a stacked bar chart in polar coordinates.” This guide gives the working recipe, explains each argument, and shows what to do when the output looks wrong.
What it is used for in research
A pie chart shows how one whole divides into parts, for example the share of participants in each study arm or the share of records in each publication type. Two official R sources urge caution before you use one. The ggplot2 reference warns: “Use these plots with caution – polar coordinates has major perceptual problems.” The base R documentation for pie() says: “Pie charts are a very bad way of displaying information. The eye is good at judging linear measures and bad at judging relative areas. A bar chart or dot chart is a preferable way of displaying this type of data.”
Use a pie only when the audience needs a quick sense of one part against the whole and you have a handful of categories. For comparing categories with each other, see the guide to a bar plot in R. For the wider question of which chart fits which data, see types of graphs in statistics.
Install or access (official source only)
ggplot2 is distributed on CRAN, R’s package repository. The CRAN package page (checked 2026-10-29) lists version 4.0.3, which depends on R 4.1 or later. Install and load it from the R console:
install.packages("ggplot2")
library(ggplot2)
Step-by-step: build a pie chart with coord_polar()
The data below are illustrative values that sum to 100, chosen so the labels read as percentages. Replace them with your own.
- Create a data frame with one row per slice: a category column and a value column.
df <- data.frame( group = c("A", "B", "C"), n = c(50, 30, 20) ) - Draw one stacked bar of width 1. Put a constant in
x, map the category tofill, and usegeom_col(width = 1)so the bar fills its whole slot. This mirrors the official example, which usesaes(x = factor(1), fill = factor(cyl))withgeom_bar(width = 1).p <- ggplot(df, aes(x = "", y = n, fill = group)) + geom_col(width = 1) - Bend the bar into a circle. Map the angle to the value axis with
theta = "y".p + coord_polar(theta = "y") - Remove the axes and grid with
theme_void(), which the ggplot2 reference describes as “a completely empty theme”.p + coord_polar(theta = "y") + theme_void() - Add labels inside the slices. The
geom_text()reference explains that to place text in the middle of each bar in a stacked bar plot you setvjustinposition_stack();position_stack(vjust = 0.5)centres each label in its segment.p + geom_text(aes(label = paste0(n, "%")), position = position_stack(vjust = 0.5)) + coord_polar(theta = "y") + theme_void() - Set the colours if the default palette does not suit.
scale_fill_brewer(palette = "Set1")applies a ColorBrewer palette to the fill; see colours in R and RStudio for more on choosing them.
Titles and legend text work as in any ggplot2 chart; see the guides to ggplot titles and ggplot legend labels.
Output and how to read it
Each slice’s angle is its share of the stacked total, so the slice for group A above covers half the circle. coord_polar() takes these arguments, as documented in the ggplot2 reference (checked 2026-10-29):
| Argument | Default | What it does (from the reference) |
|---|---|---|
theta |
"x" |
The variable to map angle to, x or y. A pie needs "y" here. |
start |
0 |
Offset of the starting point from 12 o’clock, in radians. |
direction |
1 |
1 is clockwise, -1 is anticlockwise. |
clip |
"on" |
Whether drawing is clipped to the plotting panel. |
Because start is in radians, a quarter turn is pi / 2. Compare slices by angle only roughly: the warnings quoted above exist because readers judge angles and areas less accurately than lengths on a common scale. If the exact values matter, print them on the slices or use a bar chart.
Troubleshooting
| Symptom | Likely cause and fix |
|---|---|
| You get concentric rings instead of slices | The default is theta = "x", which the reference calls a “bullseye”. Add theta = "y" to coord_polar(). |
| The pie is a single colour with no slices | No variable is mapped to fill. Add fill = group (your category column) inside aes(). |
| Slices run the wrong way round the circle | Set direction = -1 for anticlockwise. |
| The first slice starts in the wrong place | Set start in radians, measured from 12 o’clock. |
| Axis text and a grey grid surround the pie | Add theme_void(). |
| Labels sit at the slice edge, not the middle | Pass position = position_stack(vjust = 0.5) to geom_text(). |
Free alternatives
| Option | How | Source |
|---|---|---|
| Base R pie chart | pie(x, labels = names(x)), where x is a vector of non-negative numbers shown as slice areas. Its clockwise and init.angle arguments set direction and start. |
R graphics::pie documentation |
| Bar chart | The R documentation names a bar chart as the preferable display. See bar plot in R. | R graphics::pie documentation, Note section |
| Dot chart | Also named in the same note as preferable, because position along a common scale is judged more accurately than angle. | R graphics::pie documentation, Note section |
For examples of charts that mislead and what to do instead, see bad data visualization examples.
FAQ
How do I make a pie chart in ggplot2?
Draw a stacked bar of width 1 with the category mapped to fill, then add coord_polar(theta = "y"). The ggplot2 reference describes a pie chart as a stacked bar chart in polar coordinates.
How do I change where the pie starts or which way it runs?
Use the start argument (an offset from 12 o’clock in radians) and direction (1 clockwise, -1 anticlockwise) in coord_polar().
Should I use a pie chart or a bar chart?
Both the ggplot2 and base R documentation caution against pie charts. The R documentation calls a bar chart or dot chart preferable, so reserve pies for a few categories where part-to-whole is the point.
Sources (official docs)
- ggplot2 reference, coord_polar(), checked 2026-10-29.
- CRAN manual for ggplot2, coord_polar, checked 2026-10-29.
- ggplot2 reference, position_stack() and geom_text(), checked 2026-10-29.
- ggplot2 reference, complete themes (theme_void), checked 2026-10-29.
- CRAN, ggplot2 package page, version 4.0.3, checked 2026-10-29.
- R documentation, graphics::pie, checked 2026-10-29.







