Plots categorical x-axis and continuous y-axis.
Inspired by Nick Cox's Stata plug-in stripplot
. As per
geom_boxplot
, boxes reach from the first to the
third quartile; whiskers extend 1.5 times the interquartile range
but not beyond the most extreme data point.
stripplot(
data,
x,
y,
contrast = NULL,
unit = NULL,
digits = 2,
jitter = TRUE,
color = NULL,
na.rm = FALSE,
printplot = FALSE
)
Data frame. Required.
Categorical variable for x-axis. Required.
Continuous variable for y-axis. Required.
If added, the mean difference between extreme categories
will be added. contrast
provides the preceding label. See example.
Defaults to NULL
(do not show contrast).
Scale to print after the point estimate for the
contrast between extreme categories.
Defaults to NULL
(no unit).
Number of digits for rounding point estimate and confidence intervals of the contrast. Defaults to 2.
Avoid overplotting of points with similar values?
Defaults to TRUE
.
Variable to color data points by. Defaults to NULL
(none).
Remove "NA" category from x-axis?
Defaults to FALSE
.
print()
the plot? Defaults to FALSE
,
i.e., just return the plot.
ggplot object, or nothing
(if plot is sent to graphics device with printplot = TRUE
).
Standard customization options for a ggplot
object can be added
on afterwards; see example.
data(mtcars)
# Basic plot
mtcars %>%
stripplot(x = gear, y = mpg)
# Add mean difference between extreme categories, reduce digits,
# add color by 'wt', add different color scale, and label,
# all using standard ggplot syntax.
mtcars %>%
stripplot(x = gear, y = mpg,
contrast = "5 vs. 3 gears", unit = "mpg\n",
digits = 1, color = wt) +
viridis::scale_color_viridis(option = "cividis") +
ggplot2::labs(y = "Miles per gallon", color = "Weight")