Make nice density plots easily. Internally, uses na.rm = TRUE
.
nice_density(
data,
variable,
group = NULL,
colours,
ytitle = "Density",
xtitle = variable,
groups.labels = NULL,
grid = TRUE,
shapiro = FALSE,
title = variable,
histogram = FALSE,
breaks.auto = FALSE,
bins = 30
)
A density plot of class ggplot
, by group (if provided), along a
reference line representing a matched normal distribution.
The data frame
The dependent variable to be plotted.
The group by which to plot the variable.
Desired colours for the plot, if desired.
An optional y-axis label, if desired.
An optional x-axis label, if desired.
The groups.labels (might rename to
xlabels
for consistency with other functions)
Logical, whether to keep the default background grid or not. APA style suggests not using a grid in the background, though in this case some may find it useful to more easily estimate the slopes of the different groups.
Logical, whether to include the p-value from the Shapiro-Wilk test on the plot.
The desired title of the plot. Can be put to NULL
to remove.
Logical, whether to add an histogram
If histogram = TRUE, then option to set bins/breaks
automatically, mimicking the default behaviour of base
R hist()
(the Sturges method). Defaults to FALSE
.
If histogram = TRUE
, then option to change the default bin (30).
Other functions useful in assumption testing:
nice_assumptions
, nice_normality
,
nice_qq
, nice_varplot
,
nice_var
. Tutorial:
https://rempsyc.remi-theriault.com/articles/assumptions