geom_dist | R Documentation |
This function works like any other geom_
type ggplot2 function. However,
this technically is not a custom geometry but instead returns a list of
geometries to plot the various components of the distribution(s). In most
instances this can be used within any ggplot2 expression. The primary
difference is this function does not use any of the ggplot2 data or aes
components.
geom_dist(
x,
quantile = 0.95,
cv,
color,
alpha = 0.2,
point_size = 0,
center_fun = mean,
legend_title = "Distribution",
...
)
x |
either a numeric vector, list of numeric vectors, or a data frame. For lists and data frames multiple density plots will be plotted. |
quantile |
the proportion to shade around the mean. Set to 0 to not shade any of the distribution. |
cv |
critical values which define the bounds of the shaded area. If specified the |
color |
the color of the distribution. If plotting more than one
distribution (i.e. |
alpha |
the transparency level used for shading the quantiles. |
point_size |
the size of the point at the center. The default is 0 which will exclude the point. |
center_fun |
the function used to determine the center of the
distribution, typically |
legend_title |
if |
... |
other parameters passed to |
a list of ggplot2 geometries.
# Plot a single distribution
x <- rnorm(n = 1000)
ggplot2::ggplot() +
geom_dist(x) +
ggplot2::geom_point(data = data.frame(x = mean(x), y = 0),
ggplot2::aes(x = x, y = y), pch = 22)
# Plot two distributions
x1 <- rnorm(1000, mean = 0, sd = 4)
x2 <- rnbinom(1000, 10, .4)
ggplot2::ggplot() + geom_dist(list(normal = x1, binomial = x2), adjust = 2)
# Plot more than one distribution using a data frame
data(mtcars)
ggplot2::ggplot() + geom_dist(mtcars[,c('mpg', 'wt')], quantile = 0.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.