Skip to contents

Create a donut plot with the text value of the percentage in the center, using ggplot_donut().

Usage

ggplot_donut_percent(p, accuracy = NULL, hsize = 4, size = 20, family = "Lato")

Arguments

p

Proportion to plot. Must be a value between 0 and 1.

accuracy

A number to round to. Use (e.g.) 0.01 to show 2 decimal places of precision. If NULL, the default, uses a heuristic that should ensure breaks have the minimum number of digits needed to show the difference between adjacent values.

Applied to rescaled data.

hsize

Size of the donut hole. Defaults to 4, and must be a non-negative value.

size

Font size to use. Defaults to 20.

family

Font family to use. Defaults to "Lato".

Details

ggplot_donut_percent() creates a data frame and calls ggplot_donut() to create the base plot, removes the legend, and adds a geom_text() centered in the plot.

The text label is formatted using scales::label_percent() with the specified accuracy.

Examples

library(showtext)

font_add_google("Lato", "Lato")
showtext_auto()
# workaround for https://github.com/yixuan/showtext/issues/51
showtext_opts(dpi = 192)

ggplot_donut_percent(0.6)