library(ggpubr) ################################################################### my_unpaired_stats <- function(lf_data , lf_stat_value = "param_value" , lf_stat_group = "mutation_info" , lf_col_statvars = "param_type" , my_paired = FALSE , stat_adj = "none"){ stat_formula = as.formula(paste0(lf_stat_value, "~", lf_stat_group)) my_stat_df = compare_means(stat_formula , group.by = lf_col_statvars , data = lf_data , paired = my_paired , p.adjust.method = stat_adj) return(my_stat_df) } ##################### # call stat function ##################### stat_results_df <- my_unpaired_stats(lf_data = lf_duet , lf_stat_value = "param_value" , lf_stat_group = "mutation_info" , lf_col_statvars = "param_type" , my_paired = FALSE , stat_adj = "none" ) y_value = "param_value" ################################# my_comparisons <- list( c("DM", "OM") ) my_ats = 22 # axis text size my_als = 20 # axis label size my_fls = 20 # facet label size my_pts = 22 # plot title size #################################### stat_bp_mut <- function(df , x_bp_cateog = "mutation_info" , y_var = "param_value" , facet_var = "param_type" , scales = "free_y" , title = "" , col_categ = "duet_outcome" , grp_comp = "my_comparisons" , stat_method = "wilcox.test" , my_paired = FALSE #, stat_label = "p.format") , stat_label = "p.signif" ) ############################# y_value = "param_value" p1 = ggplot(lf_duet, aes(x = mutation_info , y = eval(parse(text = y_value)) )) + facet_wrap(~ param_type , nrow = 1 , scales = "free_y") + geom_boxplot(fill = "white", outlier.colour = NA #, position = position_dodge(width = 0.9) , width = 0.2) + geom_point(position = position_jitterdodge(dodge.width=0.01) , alpha = 0.5 , show.legend = FALSE , aes(colour = factor(duet_outcome))) + theme(axis.text.x = element_text(size = my_ats) , axis.text.y = element_text(size = my_ats , angle = 0 , hjust = 1 , vjust = 0) , axis.title.x = element_text(size = my_ats) , axis.title.y = element_text(size = my_ats) , plot.title = element_text(size = my_pts , hjust = 0.5, colour = "black", face = "bold") , strip.background = element_rect(fill = "khaki2") , strip.text.x = element_text(size = my_fls, colour = "black") , legend.title = element_text(color = "black", size = my_als) , legend.text = element_text(size = my_ats) , legend.direction = "vertical") + labs(title = "DUET" , x = "" , y = "")+ stat_compare_means(comparisons = my_comparisons , method = "wilcox.test" , paired = FALSE #, label = "p.format") , label = "p.signif") p1