Learn R Programming

ggstatsplot (version 0.5.0)

histo_labeller: Custom function for adding labeled lines for x-axis variable.

Description

Helper function for adding centrality parameter value and/or a test value for the continuous, numeric x-axis variable.

Usage

histo_labeller(
  plot,
  x,
  y.label.position,
  test.value = 0,
  test.k = 0,
  test.value.line = FALSE,
  test.value.line.args = list(size = 1),
  test.value.label.args = list(),
  centrality.parameter = "mean",
  centrality.k = 2,
  centrality.line.args = list(color = "blue", size = 1),
  centrality.label.args = list(color = "blue"),
  ...
)

Arguments

plot

A ggplot object for which the labeled lines need to be added for a test value and/or a centrality parameter (mean/median) value.

x

A numeric variable from the dataframe data.

test.value

A number specifying the value of the null hypothesis (Default: 0).

test.k

Integer denoting the number of decimal places expected for test.value label. (Default: 0 ).

test.value.line

Logical that decides whether a line corresponding to the test.value should be superimposed on the plot.

test.value.line.args

A list of additional aesthetic arguments to be passed to the geom_line used to display the line corresponding to test.value.

centrality.parameter

Decides which measure of central tendency ("mean" or "median") is to be displayed as a vertical line. To not show any parameter, set this to "none".

centrality.k

Integer denoting the number of decimal places expected for centrality parameter label. (Default: 2).

centrality.line.args, test.value.line.args

A list of additional aesthetic arguments to be passed to the geom_line used to display the lines corresponding to the centrality parameter and test value.

centrality.label.args, test.value.label.args

A list of additional aesthetic arguments to be passed to the geom_label used to display the label corresponding to the centrality parameter and test value.

...

Currently ignored.

Examples

Run this code
# NOT RUN {
library(ggplot2)

# creating a plot; lines and labels will be superposed on this plot
p <- ggplot(mtcars, aes(wt, mpg)) +
  geom_point()

# computing `y`-axis positions for line labels
y_label_pos <- median(
  x = ggplot2::layer_scales(p)$y$range$range,
  na.rm = TRUE
)
# adding labels
ggstatsplot:::histo_labeller(
  plot = p,
  x = mtcars$wt,
  y.label.position = y_label_pos,
  test.value.line = TRUE
)
# }

Run the code above in your browser using DataLab