Skip to content

Commit

Permalink
importing after_stat from ggplot2 #544
Browse files Browse the repository at this point in the history
  • Loading branch information
kassambara committed Feb 6, 2023
1 parent aa82b24 commit e1ce917
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions R/stat_compare_means.R
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,13 @@ StatCompareMeans<- ggproto("StatCompareMeans", Stat,

# Update mapping with label
.update_mapping <- function (mapping, label){

allowed.label <- list(
"p.signif" = quote(after_stat(p.signif)),
"..p.signif.." = quote(after_stat(p.signif)),
"p.format" = quote(after_stat(paste0("p = ", p.format))),
"..p.format.." = quote(after_stat(paste0("p = ", p.format))),
"p" = quote(after_stat(paste0("p = ", p.format))),
"..p.." = quote(after_stat(paste0("p = ", p.format)))
"p.signif" = quote(ggplot2::after_stat(p.signif)),
"..p.signif.." = quote(ggplot2::after_stat(p.signif)),
"p.format" = quote(ggplot2::after_stat(paste0("p = ", p.format))),
"..p.format.." = quote(ggplot2::after_stat(paste0("p = ", p.format))),
"p" = quote(ggplot2::after_stat(paste0("p = ", p.format))),
"..p.." = quote(ggplot2::after_stat(paste0("p = ", p.format)))
)

if(!is.null(label)){
Expand Down Expand Up @@ -338,15 +337,15 @@ convert_label_dotdot_notation_to_after_stat <- function(mapping){
if(!is.null(mapping$label)){
label <- rlang::as_label(mapping$label)
label <- gsub(
pattern = "..p.signif..", replacement = "after_stat(p.signif)",
pattern = "..p.signif..", replacement = "ggplot2::after_stat(p.signif)",
x = label, fixed = TRUE
)
label <- gsub(
pattern = "..p.format..", replacement = "after_stat(p.format)",
pattern = "..p.format..", replacement = "ggplot2::after_stat(p.format)",
x = label, fixed = TRUE
)
label <- gsub(
pattern = "..p..", replacement = "after_stat(p)",
pattern = "..p..", replacement = "ggplot2::after_stat(p)",
x = label, fixed = TRUE
)
mapping$label <- parse(text = label)[[1]]
Expand Down

0 comments on commit e1ce917

Please sign in to comment.