Scatterplot with marginal distributions for all levels of a grouping variable
Grouped scatterplots from ggplot2
combined with marginal distribution plots
with statistical details added as a subtitle.
grouped_ggscatterstats( data, x, y, grouping.var, label.var = NULL, label.expression = NULL, output = "plot", plotgrid.args = list(), annotation.args = list(), ... )
data |
A dataframe (or a tibble) from which variables specified are to be taken. Other data types (e.g., matrix,table, array, etc.) will not be accepted. |
x |
The column in |
y |
The column in |
grouping.var |
A single grouping variable (can be entered either as a
bare name |
label.var |
Variable to use for points labels. Can be entered either as
a bare expression (e.g, |
label.expression |
An expression evaluating to a logical vector that
determines the subset of data points to label. This argument can be entered
either as a bare expression (e.g., |
output |
Character that describes what is to be returned: can be
|
plotgrid.args |
A |
annotation.args |
A |
... |
Arguments passed on to
|
# to ensure reproducibility set.seed(123) library(ggstatsplot) # skipping marginal distributions so that the examples run fast # basic function call grouped_ggscatterstats( data = dplyr::filter(movies_long, genre == "Comedy" | genre == "Drama"), x = length, y = rating, type = "robust", grouping.var = genre, marginal = FALSE, ggplot.component = list(ggplot2::geom_rug(sides = "b")) ) # using labeling # (also show how to modify basic plot from within function call) grouped_ggscatterstats( data = dplyr::filter(ggplot2::mpg, cyl != 5), x = displ, y = hwy, grouping.var = cyl, type = "robust", marginal = FALSE, label.var = manufacturer, label.expression = hwy > 25 & displ > 2.5, ggplot.component = ggplot2::scale_y_continuous(sec.axis = ggplot2::dup_axis()) ) # labeling without expression grouped_ggscatterstats( data = dplyr::filter( .data = movies_long, rating == 7, genre %in% c("Drama", "Comedy") ), x = budget, y = length, grouping.var = genre, bf.message = FALSE, label.var = "title", marginal = FALSE, annotation.args = list(tag_levels = "a") )
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.