Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse labels as expressions #11

Merged
merged 8 commits into from
Jun 24, 2021
Merged

Parse labels as expressions #11

merged 8 commits into from
Jun 24, 2021

Conversation

csdaw
Copy link
Owner

@csdaw csdaw commented Jun 17, 2021

This PR addresses the label text formatting feature request raised in #10.

Now the text in the label column can be parsed as a plotmath expression, as in geom_text().

See an example below:

library(magrittr)
library(ggplot2)
library(ggprism)
# also use rstatix

p <- ggplot(ToothGrowth, aes(x = factor(dose), y = len)) + 
  geom_boxplot(aes(fill = dose), colour = "black") + 
  theme_prism() + 
  theme(legend.position = "none")

stat.test <- rstatix::t_test(ToothGrowth, len ~ dose, ref.group = "0.5") %>% 
  rstatix::add_xy_position()

stat.test$p.exprs <- paste0("P==1*x*10^", round(log10(stat.test$p.adj), 0))

p + add_pvalue(stat.test, label = "p.exprs", parse = TRUE)

Created on 2021-06-17 by the reprex package (v1.0.0)

@csdaw csdaw merged commit e21c3ee into master Jun 24, 2021
@csdaw csdaw deleted the parse-label branch June 24, 2021 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant