updated boxplot_stat_function to now take custom order of mediators to plot

This commit is contained in:
Tanushree Tunstall 2022-11-18 17:19:06 +00:00
parent 1f9e5f4e8c
commit dc7e277a72

View file

@ -23,8 +23,12 @@ getwd()
is.error <- function(x) inherits(x, "try-error")
doMyPlotsStats <- function(df) {
doMyPlotsStats <- function(df, custom_order=NULL) {
if(!is.null(custom_order)){
mediators = custom_order
} else{
mediators = levels(as.factor(df$mediator))
}
plots <- list()
@ -44,7 +48,7 @@ doMyPlotsStats <- function(df) {
#, palette = c("#00BFC4", "#F8766D")
))+
scale_colour_manual(values=c("#00BFC4", "#F8766D")) +
theme(axis.text.x = element_text(size = 15)
theme(axis.text.x = element_text(size = 10)
, axis.text.y = element_text(size = 15
, angle = 0
, hjust = 1
@ -52,8 +56,12 @@ doMyPlotsStats <- function(df) {
, axis.title.x = element_blank()
, axis.title.y = element_blank()
, legend.position = "none"
, plot.subtitle = element_text(size = 20, hjust = 0.5)
, plot.title = element_text(size = 20, hjust = 0.5)) +
, plot.subtitle = element_text(size = 14, hjust = 0.5)
, plot.title = element_text(size = 14, hjust = 0.5)
#, panel.grid.major = element_blank()
, panel.grid.minor = element_blank()
) +
labs(title = i)
#--------
@ -66,7 +74,7 @@ doMyPlotsStats <- function(df) {
group_by(timepoint, mediator) %>%
wilcox_test(value ~ obesity, paired = F) %>%
add_significance("p")
stat_df$p_format = round(stat_df$p, digits = 3)
stat_df$p_format = round(stat_df$p, digits = 2)
stat_df <- stat_df %>%
add_xy_position(x = "timepoint", dodge = 0.8)