% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ggdonutchart.R
\name{ggdonutchart}
\alias{ggdonutchart}
\title{Donut chart}
\usage{
ggdonutchart(
  data,
  x,
  label = x,
  lab.pos = c("out", "in"),
  lab.adjust = 0,
  lab.font = c(4, "plain", "black"),
  label.repel = FALSE,
  font.family = "",
  color = "black",
  fill = "white",
  palette = NULL,
  size = NULL,
  ggtheme = theme_pubr(),
  ...
)
}
\arguments{
\item{data}{a data frame}

\item{x}{variable containing values for drawing.}

\item{label}{variable specifying the label of each slice.}

\item{lab.pos}{character specifying the position for labels. Allowed values
are "out" (for outside) or "in" (for inside).}

\item{lab.adjust}{numeric value, used to adjust label position when lab.pos =
"in". Increase or decrease this value to see the effect.}

\item{lab.font}{a vector of length 3 indicating respectively the size (e.g.:
14), the style (e.g.: "plain", "bold", "italic", "bold.italic") and the
color (e.g.: "red") of label font. For example \emph{lab.font= c(4, "bold",
"red")}.}

\item{label.repel}{logical. Default is FALSE. If TRUE, the slice labels are
placed around the chart with \code{ggrepel::geom_text_repel()} and connected
to their slice with leader lines, so that the labels of many small slices no
longer overlap. When TRUE, \code{lab.pos} is ignored.}

\item{font.family}{character vector specifying font family.}

\item{color, fill}{outline and fill colors.}

\item{palette}{the color palette to be used for coloring or filling by groups.
Allowed values include "grey" for grey color palettes; brewer palettes e.g.
"RdBu", "Blues", ...; or custom color palette e.g. c("blue", "red"); and
scientific journal palettes from ggsci R package, e.g.: "npg", "aaas",
"lancet", "jco", "ucscgb", "uchicago", "simpsons" and "rickandmorty".}

\item{size}{Numeric value (e.g.: size = 1). change the size of points and
outlines.}

\item{ggtheme}{function, ggplot2 theme name. Default value is theme_pubr(). Set ggtheme = NULL to skip applying a ggpubr theme, so the plot keeps ggplot2 default theme or the theme set globally via theme_set().
Allowed values include ggplot2 official themes: theme_gray(), theme_bw(),
theme_minimal(), theme_classic(), theme_void(), ....}

\item{...}{other arguments to be passed to be passed to ggpar().}
}
\description{
Create a donut chart.
}
\details{
The plot can be easily customized using the function ggpar(). Read
 ?ggpar for changing: \itemize{ \item main title and axis labels: main, xlab,
 ylab \item axis limits: xlim, ylim (e.g.: ylim = c(0, 30)) \item axis
 scales: xscale, yscale (e.g.: yscale = "log2") \item color palettes: palette
 = "Dark2" or palette = c("gray", "blue", "red") \item legend title, labels
 and position: legend = "right" \item plot orientation : orientation =
 c("vertical", "horizontal", "reverse") }
}
\examples{

# Data: Create some data
# +++++++++++++++++++++++++++++++

df <- data.frame(
  group = c("Male", "Female", "Child"),
  value = c(25, 25, 50)
)

head(df)


# Basic pie charts
# ++++++++++++++++++++++++++++++++

ggdonutchart(df, "value", label = "group")


# Change color
# ++++++++++++++++++++++++++++++++

# Change fill color by group
# set line color to white
# Use custom color palette
ggdonutchart(df, "value",
  label = "group",
  fill = "group", color = "white",
  palette = c("#00AFBB", "#E7B800", "#FC4E07")
)


# Change label
# ++++++++++++++++++++++++++++++++

# Show group names and value as labels
labs <- paste0(df$group, " (", df$value, "\%)")
ggdonutchart(df, "value",
  label = labs,
  fill = "group", color = "white",
  palette = c("#00AFBB", "#E7B800", "#FC4E07")
)

# Change the position and font color of labels
ggdonutchart(df, "value",
  label = labs,
  lab.pos = "in", lab.font = "white",
  fill = "group", color = "white",
  palette = c("#00AFBB", "#E7B800", "#FC4E07")
)

}
\seealso{
\code{\link{ggpar}}, \code{\link{ggpie}}
}
