Learn R Programming

descsuppRplots (version 1.0)

w.ggscatterstats: Wrapper for ggstatsplot::ggscatterstats with optional p-value annotation

Description

This function creates a `ggscatterstats` plot from `ggstatsplot`, and optionally adds a p-value annotation based on values in `ldat`. It can also format the y-axis as dates.

Usage

w.ggscatterstats(data, parameter, groupby, pval.display = FALSE, ldat, ...)

Value

A ggplot object.

Arguments

data

A data frame with the data to be plotted.

parameter

Character. Name of the column in data to the values to be plotted.

groupby

Character. Name of the grouping (categorical) variable in data.

pval.display

Logical. If TRUE and there are exactly two groups in groupby, a p-value annotation is added.

ldat

A data frame containing the p-value(s) to annotate on the plot. Expected columns: `"p value"` and/or `"adjusted p value"`.

...

Additional arguments passed to ggscatterstats.

Author

Fabian Kück

Details

If groupby is not NULL and there are exactly two levels in the grouping variable, and pval.display = TRUE, a p-value from ldat is added between the two groups using geom_signif. If "adjusted p value" is present in ldat, it is used; otherwise, "p value" is used. If wasDate is TRUE, the y-axis labels are formatted as dates.

Examples

Run this code
## plot
p <- w.ggscatterstats(mtcars, parameter = "cyl", groupby = "carb",
                      bf.message = FALSE,)
if (FALSE) print(p)

## plot with p value annotation
pval <- cor.test(~ cyl + carb, data = mtcars, method = "kendall")$p.value
pval <- descutils::prettyPvalues(pval, digits = 3, orgbold = FALSE, lhs = "p")
ldat <- data.frame(`p value` = pval, check.names = FALSE)
p <- w.ggscatterstats(mtcars, parameter = "cyl", groupby = "carb", pval.display = TRUE, ldat = ldat,
                      bf.message = FALSE,)
if (FALSE) print(p)

Run the code above in your browser using DataLab