File: add_summary.Rd

package info (click to toggle)
r-cran-ggpubr 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,240 kB
  • sloc: makefile: 2
file content (157 lines) | stat: -rw-r--r-- 5,145 bytes parent folder | download
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/add_summary.R
\name{add_summary}
\alias{add_summary}
\alias{mean_se_}
\alias{mean_sd}
\alias{mean_ci}
\alias{mean_range}
\alias{median_iqr}
\alias{median_hilow_}
\alias{median_q1q3}
\alias{median_mad}
\alias{median_range}
\title{Add Summary Statistics onto a ggplot.}
\usage{
add_summary(
  p,
  fun = "mean_se",
  error.plot = "pointrange",
  color = "black",
  fill = "white",
  group = 1,
  width = NULL,
  shape = 19,
  size = 1,
  linetype = 1,
  show.legend = NA,
  ci = 0.95,
  data = NULL,
  position = position_dodge(0.8)
)

mean_se_(x, error.limit = "both")

mean_sd(x, error.limit = "both")

mean_ci(x, ci = 0.95, error.limit = "both")

mean_range(x, error.limit = "both")

median_iqr(x, error.limit = "both")

median_hilow_(x, ci = 0.95, error.limit = "both")

median_q1q3(x, error.limit = "both")

median_mad(x, error.limit = "both")

median_range(x, error.limit = "both")
}
\arguments{
\item{p}{a ggplot on which you want to add summary statistics.}

\item{fun}{a function that is given the complete data and should return a data
frame with variables ymin, y, and ymax. Allowed values are one of: "mean",
"mean_se", "mean_sd", "mean_ci", "mean_range", "median", "median_iqr",
"median_hilow", "median_q1q3", "median_mad", "median_range".}

\item{error.plot}{plot type used to visualize error. Allowed values are one of
\code{c("pointrange", "linerange", "crossbar", "errorbar", "upper_errorbar",
"lower_errorbar", "upper_pointrange", "lower_pointrange", "upper_linerange",
"lower_linerange")}. Default value is "pointrange".}

\item{color}{point or outline color.}

\item{fill}{fill color. Used only whne \code{error.plot = "crossbar"}.}

\item{group}{grouping variable. Allowed values are 1 (for one group) or a
character vector specifying the name of the grouping variable. Used only for
adding statistical summary per group.}

\item{width}{numeric value between 0 and 1 specifying bar or box width.
Example width = 0.8. Used only when \code{error.plot} is one of
c("crossbar", "errorbar").}

\item{shape}{point shape. Allowed values can be displayed using the function
\code{\link{show_point_shapes}()}.}

\item{size}{numeric value in [0-1] specifying point and line size.}

\item{linetype}{line type.}

\item{show.legend}{logical. Should this layer be included in the legends? NA,
the default, includes if any aesthetics are mapped. \code{FALSE} never includes,
and TRUE always includes. It can also be a named logical vector to finely
select the aesthetics to display.}

\item{ci}{the percent range of the confidence interval (default is 0.95).}

\item{data}{a \code{data.frame} to be displayed. If \code{NULL}, the default,
the data is inherited from the plot data as specified in the call to
\link[ggplot2]{ggplot}.}

\item{position}{position adjustment, either as a string, or the result of a
call to a position adjustment function. Used to adjust position for multiple
groups.}

\item{x}{a numeric vector.}

\item{error.limit}{allowed values are one of ("both", "lower", "upper",
"none") specifying whether to plot the lower and/or the upper limits of
error interval.}
}
\description{
add summary statistics onto a ggplot.
}
\section{Functions}{
\itemize{
\item \code{add_summary()}: add summary statistics onto a ggplot.

\item \code{mean_se_()}: returns the \code{mean} and the error limits defined by the
\code{standard error}. We used the name \code{mean_se_}() to avoid masking \code{\link[ggplot2]{mean_se}}().

\item \code{mean_sd()}: returns the \code{mean} and the error limits defined by the
\code{standard deviation}.

\item \code{mean_ci()}: returns the \code{mean} and the error limits defined by the
\code{confidence interval}.

\item \code{mean_range()}: returns the \code{mean} and the error limits defined by the
\code{range = max - min}.

\item \code{median_iqr()}: returns the \code{median} and the error limits
defined by the \code{interquartile range}.

\item \code{median_hilow_()}: computes the sample median and a selected pair of
outer quantiles having equal tail areas. This function is a reformatted
version of \code{Hmisc::smedian.hilow()}. The confidence limits are computed
as follow: \code{lower.limits = (1-ci)/2} percentiles; \code{upper.limits =
(1+ci)/2} percentiles. By default (\code{ci = 0.95}), the 2.5th and the
97.5th percentiles are used as the lower and the upper confidence limits,
respectively. If you want to use the 25th and the 75th percentiles as the
confidence limits, then specify \code{ci = 0.5} or use the function
\code{median_q1q3()}.

\item \code{median_q1q3()}: computes the sample median and, the 25th and 75th
percentiles. Wrapper around the function \code{median_hilow_()} using
\code{ci = 0.5}.

\item \code{median_mad()}: returns the \code{median} and the error limits
defined by the \code{median absolute deviation}.

\item \code{median_range()}: returns the \code{median} and the error limits
defined by the \code{range = max - min}.

}}
\examples{

# Basic violin plot
p <- ggviolin(ToothGrowth, x = "dose", y = "len", add = "none")
p

# Add mean_sd
add_summary(p, "mean_sd")


}