-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Are there any vingnettes/examples of how to use statsExpressions to create labels for customized plots? I am trying to transition to this approach (as is recommended in ggstatsplots) to have more control over aesthetics.
I have tried to follow the example provided https://indrajeetpatil.github.io/statsExpressions/ to use centrality_description() for example.
My custom raincloud plot:
ggplot(df_s, aes(x = test_percent, y = pretty_condition, fill=pretty_condition)) +
stat_slab(
geom = "slab",
position = position_nudge(y = .20), # nudged up by .20
scale = .5) +
geom_boxplot(aes(fill = NULL),
width = .20,
size = 0.5,
show.legend = FALSE,
alpha = .25) +
geom_point(aes(color = pretty_condition),
position = position_jitter(width = .01, height = .05),
size = 1.0,
shape = 19, # circles
alpha = .5) +
labs(title = "Distribution of Test Phase Accuracy",
x = "Test Phase Proportion Correct", y = "Condition") +
theme(legend.position = "blank") However, when I try to adapt this to use statsExpressions via the example:
centrality_description(df_s, y = test_percent, x = pretty_condition) |>
ggplot(aes(y = test_percent, x = pretty_condition)) +
geom_point() +
geom_label(aes(label = expression), parse = TRUE, nudge_y = -0.05) +
coord_flip()+
stat_slab(
geom = "slab",
position = position_nudge(y = .20), # nudged up by .20
scale = .5) +
geom_boxplot(aes(fill = NULL),
width = .20,
size = 0.5,
show.legend = FALSE,
alpha = .25) +
geom_point(aes(color = pretty_condition),
position = position_jitter(width = .01, height = .05),
size = 1.0,
shape = 19, # circles
alpha = .5) +
labs(title = "Distribution of Test Phase Accuracy",
x = "Test Phase Proportion Correct", y = "Condition") +
theme(legend.position = "blank") the custom plot geoms are not rendered. It is as if the mappings declared in centrality_description() are not passed along to them?
.
My goal is to create something like this:

BUT without having to manually hack the layers
p <- ggbetweenstats(data = df_s, x = pretty_condition, y = test_percent,
plot.type = "box", type = "nonparametric",
centrality.type = "parametric",
package = "RColorBrewer",
palette = "PRGn",
#boxplot.args = DOESN'T EXIST
centrality.point.args = list(color="black", size = 3, shape = 1),
point.args = list(alpha=0), #suppress points
ggplot.component = ## modify further with `{ggplot2}` functions
list(
aes(color = pretty_condition, fill = pretty_condition),
scale_colour_manual(values = paletteer::paletteer_c("viridis::viridis", 3)),
scale_fill_manual(values = paletteer::paletteer_c("viridis::viridis", 3)))
) +
ggdist::stat_halfeye(
alpha = 0.7,
point_colour = NA,
adjust = .5,
width = .5, .width = 0,
justification = -.5) +
geom_boxplot(
alpha = 0.1,
width = .2,
outlier.shape = NA
) +
geom_point(
size = 2,
alpha = .5,
position = position_jitter(
seed = 1, width = .05, height = .02
)
) +
coord_flip() + theme_clean() + theme(legend.position = "blank")
p$layers[[3]]=NULL #remove ggstatsplot boxplot; not customizable via args
e <- statsExpressions::oneway_anova(data = df_s, x = pretty_condition, y = test_percent,
type = "nonparametric") #gen stats test
p + labs(title = "Distribution of Test Phase Accuracy",
y = "Proportion of correct responses in test phase", x = "",
subtitle = "Impasse condition yields higher scores and greater variance",
caption=e$expression[[1]])
[edit] I see there is a mistake in the code above, I should be using two_sample_test rather than oneway_anova in the statsExpressions statement, above.
Thanks for the support, and for this awesome package!
