Draws a histogram, a density curve, or both, optionally split by a grouping variable. A quick first look at a continuous variable.
Usage
explore_distribution(
data,
x,
group = NULL,
type = c("histogram", "density", "both"),
bins = 30,
alpha = 0.6,
position = NULL,
palette = NULL,
facet = FALSE,
legend_inside = FALSE,
title = NULL,
x_lab = NULL
)Arguments
- data
A data frame.
- x
The continuous variable to display. Either a string or an unquoted column name.
- group
Optional grouping variable (string or unquoted name) mapped to colour/fill.
- type
One of
"histogram","density"or"both".- bins
Number of histogram bins.
- alpha
Fill transparency (useful when groups overlap).
- position
Histogram position adjustment, e.g.
"identity","stack"or"dodge". The default (NULL) chooses"dodge"whengroupis set (so overlapping bars stay readable) and"identity"otherwise.- palette
Colours for the groups; defaults to
depictr_palette().- facet
When a
groupis given, draw one panel per group instead of overlaying them. This is much clearer than an overlay once there are more than two or three groups (overlaid histograms in particular become hard to read). Defaults toFALSE. Ignored when there is nogroup.- legend_inside
When
TRUE(and agroupis given withoutfacet), draw the colour legend inside the panel (in the top-right corner a unimodal histogram/density leaves empty) over a translucent background, instead of in a right-hand margin. Defaults toFALSE.- title, x_lab
Plot title and x-axis label (defaults to the variable name).
Value
A ggplot2::ggplot object.



