| Title: | Generate Plots for All Variables in Descriptive Tables |
|---|---|
| Description: | Visualizes variables from descriptive tables produced by 'descsuppR::buildDescrTbl()' using 'ggstatsplot'. It automatically maps each variable to a suitable 'ggstatsplot' plotting function based on the applied or suggested statistical test. Users can override the automatic mapping via a named list of plot specifications. The package supports grouped and ungrouped tables, and forwards additional arguments to the underlying 'ggstatsplot' functions, providing quick, reproducible, and customizable default visualizations for descriptive summaries. |
| Authors: | Andreas Leha [aut], Fabian Kück [aut, cre] |
| Maintainer: | Fabian Kück <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0 |
| Built: | 2026-05-14 07:51:24 UTC |
| Source: | https://github.com/cran/descsuppRplots |
Report default plot functions
get_plotfun_defaults()get_plotfun_defaults()
tibble with the currently set default suggestions for plotting function
Dr. Andreas Leha
get_plotfun_defaults()get_plotfun_defaults()
Using as underlying functions the plot functions from
ggstatsplot this package visualizes the variables in a
descriptive table generated via
buildDescrTbl.
plotDescTbl( dtab, plotfuns = NULL, verbose = 0, pairwise.display = "none", pval.display = FALSE, ... )plotDescTbl( dtab, plotfuns = NULL, verbose = 0, pairwise.display = "none", pval.display = FALSE, ... )
dtab |
|
plotfuns |
named list of tibbles. names must be in |
verbose |
logical or integer. Level of verbosity. If
|
pairwise.display |
Decides if and which pairwise comparisons are shown in the plots. Available options are: - '"none"' - '"significant"' (abbreviation accepted: '"s"') - '"non-significant"' (abbreviation accepted: '"ns"') - '"all"' Defaults to "none". |
pval.display |
logical. If |
... |
additional parameters will be passed to the plotting functions. |
tibble with column p containing the plots.
Dr. Andreas Leha
ttt <- data.frame(data="training set", age=runif(100, 0, 100), sex=as.factor(sample(c("m","f"), 100, replace=TRUE, prob=c(0.3, 0.7))), score=factor(sample(1:5, 100, replace=TRUE), ordered=TRUE, levels=1:5)) ttt2 <- data.frame(data="test set", age=runif(100, 0, 100), sex=as.factor(sample(c("m","f"), 100, replace=TRUE, prob=c(0.5,0.5))), score=factor(sample(1:5, 100, replace=TRUE), ordered=TRUE, levels=1:5)) ## ungrouped table and plots dtab <- buildDescrTbl(dplyr::mutate(rbind(ttt, ttt2), data = as.factor(data)), includeNAs=TRUE, dopvals = TRUE) plotDescTbl(dtab) ## grouped table and plots dtab <- buildDescrTbl(dplyr::mutate(rbind(ttt, ttt2), data = as.factor(data)), groupby="data", includeNAs=TRUE, dopvals = TRUE) plotDescTbl(dtab)ttt <- data.frame(data="training set", age=runif(100, 0, 100), sex=as.factor(sample(c("m","f"), 100, replace=TRUE, prob=c(0.3, 0.7))), score=factor(sample(1:5, 100, replace=TRUE), ordered=TRUE, levels=1:5)) ttt2 <- data.frame(data="test set", age=runif(100, 0, 100), sex=as.factor(sample(c("m","f"), 100, replace=TRUE, prob=c(0.5,0.5))), score=factor(sample(1:5, 100, replace=TRUE), ordered=TRUE, levels=1:5)) ## ungrouped table and plots dtab <- buildDescrTbl(dplyr::mutate(rbind(ttt, ttt2), data = as.factor(data)), includeNAs=TRUE, dopvals = TRUE) plotDescTbl(dtab) ## grouped table and plots dtab <- buildDescrTbl(dplyr::mutate(rbind(ttt, ttt2), data = as.factor(data)), groupby="data", includeNAs=TRUE, dopvals = TRUE) plotDescTbl(dtab)
Change default plot functions
set_plotfun_defaults(df)set_plotfun_defaults(df)
df |
|
invisible. tibble with the old (prior to the change) set default suggestions for plotting function
Dr. Andreas Leha
current <- get_plotfun_defaults() current$plotfun[current$test == "Fisher's Exact Test for Count Data"] <- "emptyplot" current$args[current$test == "Fisher's Exact Test for Count Data"] <- list(NULL) set_plotfun_defaults(current)current <- get_plotfun_defaults() current$plotfun[current$test == "Fisher's Exact Test for Count Data"] <- "emptyplot" current$args[current$test == "Fisher's Exact Test for Count Data"] <- list(NULL) set_plotfun_defaults(current)
The plot suggestion is based on the test that was used for that variable.
suggestPlot(ltest)suggestPlot(ltest)
ltest |
character vector of tests. This normally filled by |
The default choice is taken from plotDescTbl_options$plotfun_defaults with the current associations.
If no test was performed than numeric variables are treated as if tested via t-tests and non-numeric variables as if tested via Fisher test.
tibble with columns plotfun an args where
plotfun is a string with the name of the function to be called to generate the plot and
args is a list of additional (besides the data) arguments
Dr. Andreas Leha
suggestPlot("Fisher's Exact Test for Count Data") suggestPlot("foobar")suggestPlot("Fisher's Exact Test for Count Data") suggestPlot("foobar")
Wrapper for ggplot2::ggplot()
w.emptyplot(data, parameter, groupby = NULL, pval.display = FALSE, ldat, ...)w.emptyplot(data, parameter, groupby = NULL, pval.display = FALSE, ldat, ...)
data |
A data frame with the data to be plotted. Ignored in this case. |
parameter |
Character. Name of the column in |
groupby |
Character (default: NULL). Name of the grouping (categorical) variable in |
pval.display |
Logical. If |
ldat |
A data frame containing the p-value(s) to annotate on the plot. Expected columns: '"p value"' and/or '"adjusted p value"'. Ignored in this case. |
... |
Additional arguments Ignored in this case. |
A ggplot object.
Dr. Andreas Leha
w.emptyplot()w.emptyplot()
This function creates a 'ggbarstats' plot from 'ggstatsplot', and optionally adds a p-value annotation using 'geom_signif' for two-group comparisons based on values in 'ldat'.
w.ggbarstats( data, parameter, groupby = NULL, pval.display = FALSE, ldat, tip_length = 4e-04, pval_y_position = 1.05, ... )w.ggbarstats( data, parameter, groupby = NULL, pval.display = FALSE, ldat, tip_length = 4e-04, pval_y_position = 1.05, ... )
data |
A data frame with the data to be plotted. |
parameter |
Character. Name of the column in |
groupby |
Character (default: NULL). Name of the grouping (categorical) variable in |
pval.display |
Logical. If |
ldat |
A data frame containing the p-value(s) to annotate on the plot. Expected columns: '"p value"' and/or '"adjusted p value"'. |
tip_length |
Numeric. Length of the annotation tips for |
pval_y_position |
Numeric. Vertical position for the p-value annotation (default: 1.05). |
... |
Additional arguments passed to |
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.
A ggplot object.
Fabian Kück
## ungrouped plot p <- w.ggbarstats(mtcars, "gear", bf.message = FALSE, proportion.test = FALSE) if (FALSE) print(p) ## grouped plot p <- w.ggbarstats(mtcars, "gear", groupby = "cyl", bf.message = FALSE, proportion.test = FALSE) if (FALSE) print(p) ## grouped plot with p value annotation for >2 groups pval <- fisher.test(mtcars$gear, mtcars$cyl)$p.value pval <- descutils::prettyPvalues(pval, digits = 3, orgbold = FALSE, lhs = "p") ldat <- data.frame(`p value` = pval, check.names = FALSE) p <- w.ggbarstats(mtcars, "gear", groupby = "cyl", pval.display = TRUE, ldat = ldat, bf.message = FALSE, proportion.test = FALSE) if (FALSE) print(p) ## grouped plot with p value annotation for two groups pval <- fisher.test(mtcars$gear, mtcars$vs)$p.value pval <- descutils::prettyPvalues(pval, digits = 3, orgbold = FALSE, lhs = "p") ldat <- data.frame(`p value` = pval, check.names = FALSE) p <- w.ggbarstats(mtcars, "gear", groupby = "vs", pval.display = TRUE, ldat = ldat, bf.message = FALSE, proportion.test = FALSE) if (FALSE) print(p)## ungrouped plot p <- w.ggbarstats(mtcars, "gear", bf.message = FALSE, proportion.test = FALSE) if (FALSE) print(p) ## grouped plot p <- w.ggbarstats(mtcars, "gear", groupby = "cyl", bf.message = FALSE, proportion.test = FALSE) if (FALSE) print(p) ## grouped plot with p value annotation for >2 groups pval <- fisher.test(mtcars$gear, mtcars$cyl)$p.value pval <- descutils::prettyPvalues(pval, digits = 3, orgbold = FALSE, lhs = "p") ldat <- data.frame(`p value` = pval, check.names = FALSE) p <- w.ggbarstats(mtcars, "gear", groupby = "cyl", pval.display = TRUE, ldat = ldat, bf.message = FALSE, proportion.test = FALSE) if (FALSE) print(p) ## grouped plot with p value annotation for two groups pval <- fisher.test(mtcars$gear, mtcars$vs)$p.value pval <- descutils::prettyPvalues(pval, digits = 3, orgbold = FALSE, lhs = "p") ldat <- data.frame(`p value` = pval, check.names = FALSE) p <- w.ggbarstats(mtcars, "gear", groupby = "vs", pval.display = TRUE, ldat = ldat, bf.message = FALSE, proportion.test = FALSE) if (FALSE) print(p)
This function creates a 'ggbetweenstats' plot from 'ggstatsplot', and optionally adds a p-value annotation using 'geom_signif' for two-group comparisons based on values in 'ldat'. If requested, it can also format the y-axis as dates.
w.ggbetweenstats( data, parameter, groupby = NULL, pval.display = FALSE, ldat, ... )w.ggbetweenstats( data, parameter, groupby = NULL, pval.display = FALSE, ldat, ... )
data |
A data frame with the data to be plotted. |
parameter |
Character. Name of the column in |
groupby |
Character (default: NULL). Name of the grouping (categorical) variable in |
pval.display |
Logical. If |
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 |
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.
A ggplot object.
Fabian Kück
## ungrouped plot p <- w.ggbetweenstats(iris, "Sepal.Length") if (FALSE) print(p) ## grouped plot p <- w.ggbetweenstats(iris, "Sepal.Length", groupby = "Species", bf.message = FALSE, pairwise.display = "none") if (FALSE) print(p) ## grouped plot with p value annotation for >2 groups pval <- anova(lm(Sepal.Length ~ Species, data = iris))['Species', 'Pr(>F)'] pval <- descutils::prettyPvalues(pval, digits = 3, orgbold = FALSE, lhs = "p") ldat <- data.frame(`p value` = pval, check.names = FALSE) p <- w.ggbetweenstats(iris, "Sepal.Length", groupby = "Species", pval.display = TRUE, ldat = ldat, bf.message = FALSE, pairwise.display = "none") if (FALSE) print(p) ## setup simple data with only two groups iris2 <- iris[iris$Species %in% c("setosa", "virginica"),] ## grouped plot with p value annotation for two groups pval <- t.test(Sepal.Length ~ Species, data = iris2)$p.value pval <- descutils::prettyPvalues(pval, digits = 3, orgbold = FALSE, lhs = "p") ldat <- data.frame(`p value` = pval, check.names = FALSE) p <- w.ggbetweenstats(iris2, "Sepal.Length", groupby = "Species", pval.display = TRUE, ldat = ldat, bf.message = FALSE, pairwise.display = "none") if (FALSE) print(p)## ungrouped plot p <- w.ggbetweenstats(iris, "Sepal.Length") if (FALSE) print(p) ## grouped plot p <- w.ggbetweenstats(iris, "Sepal.Length", groupby = "Species", bf.message = FALSE, pairwise.display = "none") if (FALSE) print(p) ## grouped plot with p value annotation for >2 groups pval <- anova(lm(Sepal.Length ~ Species, data = iris))['Species', 'Pr(>F)'] pval <- descutils::prettyPvalues(pval, digits = 3, orgbold = FALSE, lhs = "p") ldat <- data.frame(`p value` = pval, check.names = FALSE) p <- w.ggbetweenstats(iris, "Sepal.Length", groupby = "Species", pval.display = TRUE, ldat = ldat, bf.message = FALSE, pairwise.display = "none") if (FALSE) print(p) ## setup simple data with only two groups iris2 <- iris[iris$Species %in% c("setosa", "virginica"),] ## grouped plot with p value annotation for two groups pval <- t.test(Sepal.Length ~ Species, data = iris2)$p.value pval <- descutils::prettyPvalues(pval, digits = 3, orgbold = FALSE, lhs = "p") ldat <- data.frame(`p value` = pval, check.names = FALSE) p <- w.ggbetweenstats(iris2, "Sepal.Length", groupby = "Species", pval.display = TRUE, ldat = ldat, bf.message = FALSE, pairwise.display = "none") if (FALSE) print(p)
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.
w.ggscatterstats(data, parameter, groupby, pval.display = FALSE, ldat, ...)w.ggscatterstats(data, parameter, groupby, pval.display = FALSE, ldat, ...)
data |
A data frame with the data to be plotted. |
parameter |
Character. Name of the column in |
groupby |
Character. Name of the grouping (categorical) variable in |
pval.display |
Logical. If |
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 |
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.
A ggplot object.
Fabian Kück
## 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)## 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)