add_test_pvalue | R Documentation |
Add statistical test
add_test_pvalue(
plot,
padding_top = 0.15,
method = "t_test",
p.adjust.method = "none",
ref.group = NULL,
comparisons = NULL,
paired_by = NULL,
label = "{format_p_value(p.adj, 0.0001)}",
label.size = 7/ggplot2::.pt,
step.increase = 0.15,
vjust = -0.25,
bracket.nudge.y = 0.1,
hide.ns = FALSE,
p.adjust.by = "panel",
symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, Inf), symbols = c("***", "**",
"*", "ns")),
hide_info = FALSE,
...
)
add_test_asterisks(
plot,
padding_top = 0.1,
method = "t_test",
p.adjust.method = "none",
ref.group = NULL,
comparisons = NULL,
paired_by = NULL,
label = "p.adj.signif",
label.size = 10/ggplot2::.pt,
step.increase = 0.2,
vjust = 0.3,
bracket.nudge.y = 0.15,
hide.ns = TRUE,
p.adjust.by = "panel",
symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, Inf), symbols = c("***", "**",
"*", "ns")),
hide_info = FALSE,
...
)
plot |
A |
padding_top |
Extra padding above the data points to accommodate the statistical comparisons. |
method |
a character string indicating which method to be used for
pairwise comparisons. Default is |
p.adjust.method |
method for adjusting p values (see
|
ref.group |
a character string or a numeric value specifying the reference group. If specified, for a given grouping variable, each of the group levels will be compared to the reference group (i.e. control group).
Allowed values can be:
|
comparisons |
A list of length-2 vectors. The entries in the vector are 2 integers that correspond to the index of the groups of interest, to be compared. |
paired_by |
Variable to be used for paired analysis. |
label |
character string specifying label. Can be:
. |
label.size |
change the size of the label text |
step.increase |
numeric vector with the increase in fraction of total height for every additional comparison to minimize overlap. |
vjust |
move the text up or down relative to the bracket. |
bracket.nudge.y |
Vertical adjustment to nudge brackets by (in fraction of the total height). Useful to move up or move down the bracket. If positive value, brackets will be moved up; if negative value, brackets are moved down. |
hide.ns |
can be logical value ( |
p.adjust.by |
possible value is one of |
symnum.args |
a list of arguments to pass to the function
In other words, we use the following convention for symbols indicating statistical significance:
|
hide_info |
Whether to hide details about the statistical testing as caption. Defaults to |
... |
Arguments passed on to |
add_test_pvalue()
and add_test_asterisks()
use ggpubr::geom_pwc()
.
Check there for additional arguments.
Known limitation: add_test_pvalue()
and add_test_asterisks()
expect a
discrete variable on the x-axis and a continuous variable on the y-axis.
To produce horizontal plots, use flip_plot()
.
A tidyplot
object.
# Add p value
study |>
tidyplot(x = dose, y = score, color = group) |>
add_mean_dash() |>
add_sem_errorbar() |>
add_data_points() |>
add_test_pvalue()
# Add asterisks
study |>
tidyplot(x = dose, y = score, color = group) |>
add_mean_dash() |>
add_sem_errorbar() |>
add_data_points() |>
add_test_asterisks()
# Change stat method
study |>
tidyplot(x = dose, y = score, color = group) |>
add_mean_dash() |>
add_sem_errorbar() |>
add_data_points() |>
add_test_pvalue(method = "wilcoxon")
# Change p.adjust method
study |>
tidyplot(x = dose, y = score, color = group) |>
add_mean_dash() |>
add_sem_errorbar() |>
add_data_points() |>
add_test_pvalue(p.adjust.method = "bonferroni")
# Define reference group to test against
study |>
tidyplot(x = treatment, y = score, color = treatment) |>
add_mean_dash() |>
add_sem_errorbar() |>
add_data_points() |>
add_test_asterisks(ref.group = 1)
# Define selected comparisons
study |>
tidyplot(x = treatment, y = score, color = treatment) |>
add_mean_dash() |>
add_sem_errorbar() |>
add_data_points() |>
add_test_pvalue(comparisons = list(c(1,3),c(2,4)))
# Paired analysis
x <- c(2.3, 4.5, 6.3, 3.4, 7.8, 6.7)
df <- data.frame(
x = c(x, x + c(0.8, 0.75)),
group = paste0("g", rep(c(1, 2), each = 6)),
batch = paste0("b", c(1:6, 1:6)),
shuffle = paste0("c", c(1:6, 6:1))
)
df |>
tidyplot(group, x, color = group) |>
add_boxplot() |>
add_data_points() |>
add_test_pvalue(paired_by = shuffle) |>
add_line(group = shuffle, color = "black")
df |>
tidyplot(group, x, color = group) |>
add_boxplot() |>
add_data_points() |>
add_test_pvalue(paired_by = batch) |>
add_line(group = batch, color = "black")
# hide non-significant p values
gene_expression |>
# filter to one gene
dplyr::filter(external_gene_name == "Apol6") |>
# start plotting
tidyplot(x = condition, y = expression, color = sample_type) |>
add_mean_dash() |>
add_sem_errorbar() |>
add_data_points() |>
add_test_pvalue(hide.ns = TRUE)
# Flip plot
study |>
tidyplot(x = treatment, y = score, color = treatment) |>
add_mean_dash() |>
add_sem_errorbar() |>
add_data_points() |>
add_test_asterisks(comparisons = list(c(1,4),c(2,3))) |>
flip_plot()
# Adjust top padding for statistical comparisons
study |>
tidyplot(x = treatment, y = score, color = treatment) |>
add_mean_dash() |>
add_sem_errorbar() |>
add_data_points() |>
add_test_pvalue(padding_top = 0.08)
# Hide stats information
study |>
tidyplot(x = dose, y = score, color = group) |>
add_mean_dash() |>
add_sem_errorbar() |>
add_data_points() |>
add_test_pvalue(hide_info = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.