testing boxplots
This commit is contained in:
parent
8358c0862c
commit
ed10be8f6e
1 changed files with 23 additions and 216 deletions
|
@ -6,230 +6,37 @@ getwd()
|
||||||
# TASK: boxplots at T1
|
# TASK: boxplots at T1
|
||||||
# FIXME: currently not rendering, problem with NAs for stats?
|
# FIXME: currently not rendering, problem with NAs for stats?
|
||||||
############################################################
|
############################################################
|
||||||
my_sample_type = "serum"
|
|
||||||
#=============
|
#=============
|
||||||
# Input
|
# Input
|
||||||
#=============
|
#=============
|
||||||
source("data_extraction_formatting.R")
|
source("boxplot_linear.R")
|
||||||
|
|
||||||
# check: adult variable and age variable discrepancy!
|
mediators = levels(as.factor(lf_test$mediator))
|
||||||
metadata_all$mosaic[metadata_all$adult==1 & metadata_all$age<=18]
|
|
||||||
|
|
||||||
#=============
|
plots <- list()
|
||||||
# Output:
|
|
||||||
#=============
|
|
||||||
outfile_bp = paste0("boxplots_", my_sample_type, ".pdf")
|
|
||||||
output_boxplot = paste0(outdir_plots, outfile_bp); output_boxplot
|
|
||||||
|
|
||||||
#===============================
|
for (i in mediators) {
|
||||||
# data assignment for plots
|
single=lf_test[lf_test$mediator==i,]
|
||||||
#================================
|
|
||||||
#wf_fp_npa = npa_wf[npa_wf$flustat == 1,]
|
|
||||||
lf_fp_npa = npa_lf[npa_lf$flustat == 1,]
|
|
||||||
lf_fp_npa$timepoint = paste0("t", lf_fp_npa$timepoint)
|
|
||||||
lf_fp_npa$timepoint = as.factor(lf_fp_npa$timepoint)
|
|
||||||
lf_fp_npa$obesity = as.factor(lf_fp_npa$obesity)
|
|
||||||
|
|
||||||
table(lf_fp_npa$mediator)
|
p2 = ggboxplot(single
|
||||||
head(lf_fp_npa$value[lf_fp_npa$mediator == "vitd"])
|
, x = "timepoint"
|
||||||
lf_fp_npa = lf_fp_npa[!lf_fp_npa$mediator == "vitd",]
|
, y = "value"
|
||||||
|
, color = "obesity"
|
||||||
|
, palette = c("#00BFC4", "#F8766D")
|
||||||
|
)
|
||||||
|
|
||||||
|
stat_npa2 <- single %>%
|
||||||
|
group_by(timepoint, mediator) %>%
|
||||||
|
wilcox_test(value ~ obesity, paired = F) %>%
|
||||||
|
add_significance("p")
|
||||||
|
stat_npa2
|
||||||
|
|
||||||
#wf_fp_sam = samm_wf[samm_wf$flustat == 1,]
|
stat_npa2 <- stat_npa2 %>%
|
||||||
lf_fp_sam = sam_lf[sam_lf$flustat == 1,]
|
add_xy_position(x = "timepoint", dodge = 0.8)
|
||||||
lf_fp_sam$timepoint = paste0("t", lf_fp_sam$timepoint)
|
|
||||||
lf_fp_sam$timepoint = as.factor(lf_fp_sam$timepoint)
|
|
||||||
lf_fp_sam$obesity = as.factor(lf_fp_sam$obesity)
|
|
||||||
|
|
||||||
table(lf_fp_sam$mediator)
|
p2 = p2 + stat_pvalue_manual(stat_npa2
|
||||||
head(lf_fp_sam$value[lf_fp_sam$mediator == "vitd"])
|
, label = "{p} {p.signif}"
|
||||||
lf_fp_sam = lf_fp_sam[!lf_fp_sam$mediator == "vitd",]
|
, hide.ns=T
|
||||||
|
, tip.length = 0)
|
||||||
|
plots[[i]] <- p2
|
||||||
#wf_fp_serum = serum_wf[serum_wf$flustat == 1,]
|
|
||||||
lf_fp_serum = serum_lf[serum_lf$flustat == 1,]
|
|
||||||
lf_fp_serum$timepoint = paste0("t", lf_fp_serum$timepoint)
|
|
||||||
lf_fp_serum$timepoint = as.factor(lf_fp_serum$timepoint)
|
|
||||||
lf_fp_serum$obesity = as.factor(lf_fp_serum$obesity)
|
|
||||||
|
|
||||||
########################################################################
|
|
||||||
cat("Output plots will be in:", output_boxplot)
|
|
||||||
pdf(output_boxplot, width = 20, height = 15)
|
|
||||||
|
|
||||||
#=======================================================================
|
|
||||||
# NPA
|
|
||||||
#=======================================================================
|
|
||||||
if (is.factor(lf_fp_npa$timepoint) && is.factor(lf_fp_npa$timepoint)){
|
|
||||||
cat ("PASS: required groups are factors")
|
|
||||||
}
|
}
|
||||||
#------------------------------------------
|
|
||||||
title_npa_linear = "Boxplot: NPA (Linear)"
|
|
||||||
#-----------------------------------------
|
|
||||||
bxp_npa_linear <- ggboxplot(lf_fp_npa, x = "timepoint", y = "value",
|
|
||||||
color = "obesity", palette = c("#00BFC4", "#F8766D")) +
|
|
||||||
facet_wrap(~mediator, nrow = 7, ncol = 5, scales = "free_y", shrink = T)+
|
|
||||||
#scale_y_log10() +
|
|
||||||
theme(axis.text.x = element_text(size = 15)
|
|
||||||
, axis.text.y = element_text(size = 15
|
|
||||||
, angle = 0
|
|
||||||
, hjust = 1
|
|
||||||
, vjust = 0)
|
|
||||||
, axis.title.x = element_text(size = 15)
|
|
||||||
, axis.title.y = element_text(size = 15)
|
|
||||||
, plot.title = element_text(size = 20, hjust = 0.5)
|
|
||||||
, strip.text.x = element_text(size = 15, colour = "black")
|
|
||||||
, legend.title = element_text(color = "black", size = 20)
|
|
||||||
, legend.text = element_text(size = 15)
|
|
||||||
, legend.direction = "horizontal") +
|
|
||||||
labs(title = title_npa_linear
|
|
||||||
, x = ""
|
|
||||||
, y = "Levels")
|
|
||||||
|
|
||||||
bxp_npa_linear
|
|
||||||
|
|
||||||
#------------------------------------
|
|
||||||
title_npa_log = "Boxplot: NPA (Log)"
|
|
||||||
#-----------------------------------
|
|
||||||
|
|
||||||
bxp_npa_log <- ggboxplot(lf_fp_npa, x = "timepoint", y = "value",
|
|
||||||
color = "obesity", palette = c("#00BFC4", "#F8766D")) +
|
|
||||||
facet_wrap(~mediator, nrow = 7, ncol = 5, scales = "free_y", shrink = F)+
|
|
||||||
scale_y_log10() +
|
|
||||||
theme(axis.text.x = element_text(size = 15)
|
|
||||||
, axis.text.y = element_text(size = 15
|
|
||||||
, angle = 0
|
|
||||||
, hjust = 1
|
|
||||||
, vjust = 0)
|
|
||||||
, axis.title.x = element_text(size = 15)
|
|
||||||
, axis.title.y = element_text(size = 15)
|
|
||||||
, plot.title = element_text(size = 20, hjust = 0.5)
|
|
||||||
, strip.text.x = element_text(size = 15, colour = "black")
|
|
||||||
, legend.title = element_text(color = "black", size = 20)
|
|
||||||
, legend.text = element_text(size = 15)
|
|
||||||
, legend.direction = "horizontal") +
|
|
||||||
labs(title = title_npa_log
|
|
||||||
, x = ""
|
|
||||||
, y = "Levels (Log)")
|
|
||||||
|
|
||||||
bxp_npa_log
|
|
||||||
|
|
||||||
#=======================================================================
|
|
||||||
# SAM
|
|
||||||
#=======================================================================
|
|
||||||
if (is.factor(lf_fp_sam$timepoint) && is.factor(lf_fp_sam$timepoint)){
|
|
||||||
cat ("PASS: required groups are factors")
|
|
||||||
}
|
|
||||||
|
|
||||||
#------------------------------------------
|
|
||||||
title_sam_linear = "Boxplot: sam (Linear)"
|
|
||||||
#-----------------------------------------
|
|
||||||
bxp_sam_linear <- ggboxplot(lf_fp_sam, x = "timepoint", y = "value",
|
|
||||||
color = "obesity", palette = c("#00BFC4", "#F8766D")) +
|
|
||||||
facet_wrap(~mediator, nrow = 7, ncol = 5, scales = "free_y", shrink = T)+
|
|
||||||
#scale_y_log10() +
|
|
||||||
theme(axis.text.x = element_text(size = 15)
|
|
||||||
, axis.text.y = element_text(size = 15
|
|
||||||
, angle = 0
|
|
||||||
, hjust = 1
|
|
||||||
, vjust = 0)
|
|
||||||
, axis.title.x = element_text(size = 15)
|
|
||||||
, axis.title.y = element_text(size = 15)
|
|
||||||
, plot.title = element_text(size = 20, hjust = 0.5)
|
|
||||||
, strip.text.x = element_text(size = 15, colour = "black")
|
|
||||||
, legend.title = element_text(color = "black", size = 20)
|
|
||||||
, legend.text = element_text(size = 15)
|
|
||||||
, legend.direction = "horizontal") +
|
|
||||||
labs(title = title_sam_linear
|
|
||||||
, x = ""
|
|
||||||
, y = "Levels")
|
|
||||||
|
|
||||||
bxp_sam_linear
|
|
||||||
|
|
||||||
#------------------------------------
|
|
||||||
title_sam_log = "Boxplot: sam (Log)"
|
|
||||||
#-----------------------------------
|
|
||||||
|
|
||||||
bxp_sam_log <- ggboxplot(lf_fp_sam, x = "timepoint", y = "value",
|
|
||||||
color = "obesity", palette = c("#00BFC4", "#F8766D")) +
|
|
||||||
facet_wrap(~mediator, nrow = 7, ncol = 5, scales = "free_y", shrink = T)+
|
|
||||||
scale_y_log10() +
|
|
||||||
theme(axis.text.x = element_text(size = 15)
|
|
||||||
, axis.text.y = element_text(size = 15
|
|
||||||
, angle = 0
|
|
||||||
, hjust = 1
|
|
||||||
, vjust = 0)
|
|
||||||
, axis.title.x = element_text(size = 15)
|
|
||||||
, axis.title.y = element_text(size = 15)
|
|
||||||
, plot.title = element_text(size = 20, hjust = 0.5)
|
|
||||||
, strip.text.x = element_text(size = 15, colour = "black")
|
|
||||||
, legend.title = element_text(color = "black", size = 20)
|
|
||||||
, legend.text = element_text(size = 15)
|
|
||||||
, legend.direction = "horizontal") +
|
|
||||||
labs(title = title_sam_log
|
|
||||||
, x = ""
|
|
||||||
, y = "Levels (Log)")
|
|
||||||
|
|
||||||
bxp_sam_log
|
|
||||||
|
|
||||||
#=======================================================================
|
|
||||||
# SERUM
|
|
||||||
#=======================================================================
|
|
||||||
if (is.factor(lf_fp_serum$timepoint) && is.factor(lf_fp_serum$timepoint)){
|
|
||||||
cat ("PASS: required groups are factors")
|
|
||||||
}
|
|
||||||
|
|
||||||
table(lf_fp_serum$mediator)
|
|
||||||
|
|
||||||
#------------------------------------------
|
|
||||||
title_serum_linear = "Boxplot: serum (Linear)"
|
|
||||||
#-----------------------------------------
|
|
||||||
bxp_serum_linear <- ggboxplot(lf_fp_serum, x = "timepoint", y = "value",
|
|
||||||
color = "obesity", palette = c("#00BFC4", "#F8766D")) +
|
|
||||||
facet_wrap(~mediator, nrow = 7, ncol = 5, scales = "free_y", shrink = T)+
|
|
||||||
#scale_y_log10() +
|
|
||||||
theme(axis.text.x = element_text(size = 15)
|
|
||||||
, axis.text.y = element_text(size = 15
|
|
||||||
, angle = 0
|
|
||||||
, hjust = 1
|
|
||||||
, vjust = 0)
|
|
||||||
, axis.title.x = element_text(size = 15)
|
|
||||||
, axis.title.y = element_text(size = 15)
|
|
||||||
, plot.title = element_text(size = 20, hjust = 0.5)
|
|
||||||
, strip.text.x = element_text(size = 15, colour = "black")
|
|
||||||
, legend.title = element_text(color = "black", size = 20)
|
|
||||||
, legend.text = element_text(size = 15)
|
|
||||||
, legend.direction = "horizontal") +
|
|
||||||
labs(title = title_serum_linear
|
|
||||||
, x = ""
|
|
||||||
, y = "Levels")
|
|
||||||
|
|
||||||
bxp_serum_linear
|
|
||||||
|
|
||||||
#------------------------------------
|
|
||||||
title_serum_log = "Boxplot: serum (Log)"
|
|
||||||
#-----------------------------------
|
|
||||||
|
|
||||||
bxp_serum_log <- ggboxplot(lf_fp_serum, x = "timepoint", y = "value",
|
|
||||||
color = "obesity", palette = c("#00BFC4", "#F8766D")) +
|
|
||||||
facet_wrap(~mediator, nrow = 7, ncol = 5, scales = "free_y", shrink = T)+
|
|
||||||
scale_y_log10() +
|
|
||||||
theme(axis.text.x = element_text(size = 15)
|
|
||||||
, axis.text.y = element_text(size = 15
|
|
||||||
, angle = 0
|
|
||||||
, hjust = 1
|
|
||||||
, vjust = 0)
|
|
||||||
, axis.title.x = element_text(size = 15)
|
|
||||||
, axis.title.y = element_text(size = 15)
|
|
||||||
, plot.title = element_text(size = 20, hjust = 0.5)
|
|
||||||
, strip.text.x = element_text(size = 15, colour = "black")
|
|
||||||
, legend.title = element_text(color = "black", size = 20)
|
|
||||||
, legend.text = element_text(size = 15)
|
|
||||||
, legend.direction = "horizontal") +
|
|
||||||
labs(title = title_serum_log
|
|
||||||
, x = ""
|
|
||||||
, y = "Levels (Log)")
|
|
||||||
|
|
||||||
bxp_serum_log
|
|
||||||
|
|
||||||
dev.off()
|
|
||||||
#==========================================================================
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue