Create a density plot with a wrapper around the ggplot2::geom_density function.
gg_density(
data = NULL,
x = NULL,
y = NULL,
col = NULL,
facet = NULL,
group = NULL,
text = NULL,
stat = "density",
position = "identity",
pal = NULL,
pal_na = "#7F7F7F",
alpha = 0.5,
...,
titles = NULL,
title = NULL,
subtitle = NULL,
coord = NULL,
x_breaks = NULL,
x_expand = NULL,
x_include = NULL,
x_labels = NULL,
x_limits = NULL,
x_oob = scales::oob_censor,
x_title = NULL,
x_trans = "identity",
y_breaks = NULL,
y_expand = NULL,
y_include = NULL,
y_labels = NULL,
y_limits = NULL,
y_oob = scales::oob_censor,
y_title = NULL,
y_trans = "identity",
col_breaks = NULL,
col_include = NULL,
col_intervals = NULL,
col_labels = NULL,
col_legend_place = NULL,
col_legend_ncol = NULL,
col_legend_nrow = NULL,
col_limits = NULL,
col_title = NULL,
facet_intervals = NULL,
facet_labels = NULL,
facet_ncol = NULL,
facet_nrow = NULL,
facet_scales = "fixed",
caption = NULL,
theme = NULL
)
A ggplot object.
A data frame or tibble.
Unquoted x aesthetic variable.
Unquoted y aesthetic variable.
Unquoted col and fill aesthetic variable.
Unquoted facet aesthetic variable.
Unquoted group aesthetic variable.
Unquoted text aesthetic variable, which can be used in combination with plotly::ggplotly(., tooltip = "text").
Statistical transformation. A character string (e.g. "identity").
Position adjustment. Either a character string (e.g."identity"), or a function (e.g. ggplot2::position_identity()).
Colours to use. A character vector of hex codes (or names).
Colour to use for NA values. A character vector of a hex code (or name).
Opacity. A number between 0 and 1.
Other arguments passed to the relevant ggplot2::geom_* function.
A function to format the x, y and col titles, including in rlang lambda format. Defaults to snakecase::to_sentence_case.
Title string.
Subtitle string.
Coordinate system.
A function that takes the limits as input (e.g. scales::breaks_pretty()), or a vector of breaks.
Padding to the limits with the ggplot2::expansion function, or a vector of length 2 (e.g. c(0, 0)).
For a numeric or date variable, any values that the scale should include (e.g. 0).
A function that takes the breaks as inputs (e.g. scales::label_comma()), or a vector of labels.
A vector of length 2 to determine the limits of the axis.
A scales::oob_* function for how to deal with out-of-bounds values.
Axis title string. Defaults to converting to sentence case with spaces. Use "" for no title.
For a numeric variable, a transformation object (e.g. "log10").
A function that takes the limits as input (e.g. scales::breaks_pretty()), or a vector of breaks.
Padding to the limits with the ggplot2::expansion function, or a vector of length 2 (e.g. c(0, 0)).
For a numeric or date variable, any values that the scale should include (e.g. 0).
A function that takes the breaks as inputs (e.g. scales::label_comma()), or a vector of labels.
A vector of length 2 to determine the limits of the axis.
A scales::oob_* function for how to deal with out-of-bounds values.
Axis title string. Defaults to converting to sentence case with spaces. Use "" for no title.
For a numeric variable, a transformation object (e.g. "log10").
A function that takes the limits as input (e.g. scales::breaks_pretty()), or a vector of breaks.
For a numeric or date variable, any values that the scale should include (e.g. 0).
A function to cut or chop the numeric variable into intervals (e.g. ~ santoku::chop_mean_sd(.x, drop = FALSE)).
A function that takes the breaks as inputs (e.g. scales::label_comma()), or a vector of labels. Note this does not affect where col_intervals is not NULL.
The place for the legend. "r" for right, "b" for bottom, "t" for top, or "l" for left.
The number of columns for the legend elements.
The number of rows for the legend elements.
A vector to determine the limits of the axis.
Axis title string. Defaults to converting to sentence case with spaces. Use "" for no title.
A function to cut or chop the numeric variable into intervals, including in rlang lambda format (e.g. ~ santoku::chop_mean_sd(.x, drop = FALSE)).
A function that takes the breaks as inputs (e.g. scales::label_comma()), or a named vector of labels (e.g. c(value = "label", ...)).
The number of columns of facetted plots.
The number of rows of facetted plots.
Whether facet_scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".
Caption title string.
A ggplot2 theme.
library(ggplot2)
gg_density(diamonds, x = carat)
gg_density(diamonds, y = carat)
gg_density(diamonds, x = carat, adjust = 1/5)
gg_density(diamonds, x = carat, adjust = 5)
gg_density(diamonds, x = depth, col = cut, x_limits = c(55, 70))
gg_density(diamonds, x = carat, col = cut, position = "stack", alpha = 0.9)
gg_density(diamonds, x = carat, col = cut, position = "fill", alpha = 0.9)
Run the code above in your browser using DataLab