Donut (doughnut) charts, also known as ring charts, are an alternative to pie charts and can be created in ggplot2 in a similar way.
The data frame below will be used in the following examples.
A donut or ring chart can be created using geom_col
, coord_polar(theta = "y")
and setting a X-axis limit with xlim
the following way.
We have developed the previous code so you can set the hole size with hsize
. The bigger the value the bigger the hole size. Note that the hole size must be bigger than 0.
You can also add labels to each slice of the donut. For that purpose you can use geom_text
or geom_label
, specifying the position as follows, so the text will be in the middle of each slice. Note that when using geom_label
is recommended show.legend = FALSE
so the legend box will not be overridden.
The border, fill colors and the theme of the donut plot can be customized in several ways. The following codes and figures display some customization examples.
Border color
Custom colors
Color palette and theme
As in other ggplot2 plots the legend can be customized in several ways. The following codes show how to change the legend key labels, the legend title or how to get rid of the legend.
Legend key labels
Legend title
Remove legend
See also