ggladder | R Documentation |
Explore Tukey's ladder of powers graphically using histograms to identify a
transform that converts var
into a normally distributed variable.
Density is shown on the y-axis. The heights of the bars of the histogram are scaled so that the sum of their areas is equal to 1.0. Normal curves are plotted using the mean and standard deviation of the transformations, not the kernel density of the histograms.
This is intended to replicate the gladder
command in Stata. As per Stata's
approach, the number of bins is set to the min(sqrt(n), 10 * log10(n))
,
rounded to the closest integer, where n is number of observations. NAs
are omitted by default.
ggladder(
data,
var,
fill = "#0072B2",
alpha = 0.8,
line_color = "black",
line_type = "solid"
)
data |
A tibble or data frame. |
var |
A numeric vector of data values. |
fill |
Fill color for the histograms (default = "#0072B2"). |
alpha |
A numeric value (0–1) specifying the transparency of the histogram fill. Default is |
line_color |
Color for the normal curves (default = "black"). |
line_type |
Line type for the normal curves (default = "solid"). |
A tibble.
https://www.stata.com/manuals/rladder.pdf
ggladder(data = auto,
var = mpg)
ggladder(data = auto,
var = mpg,
fill = "pink")
# To adjust the theme of all of the patches using patchwork package and an &
# instead of +
ggladder(data = auto,
var = mpg) &
ggplot2::theme_classic()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.