1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ggpie.R
\name{ggpie}
\alias{ggpie}
\title{Pie chart}
\usage{
ggpie(
data,
x,
label = x,
lab.pos = c("out", "in"),
lab.adjust = 0,
lab.font = c(4, "plain", "black"),
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{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().
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 pie 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
# ++++++++++++++++++++++++++++++++
ggpie(df, "value", label = "group")
# Reducing margins around the pie chart
ggpie(df, "value", label = "group") +
theme( plot.margin = unit(c(-.75,-.75,-.75,-.75),"cm"))
# Change color
# ++++++++++++++++++++++++++++++++
# Change fill color by group
# set line color to white
# Use custom color palette
ggpie(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, "\%)")
ggpie(df, "value", label = labs,
fill = "group", color = "white",
palette = c("#00AFBB", "#E7B800", "#FC4E07"))
# Change the position and font color of labels
ggpie(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{ggline}}
}
|