diff --git a/boxplot_linear_na.R b/boxplot_linear_na.R new file mode 100644 index 0000000..12f883e --- /dev/null +++ b/boxplot_linear_na.R @@ -0,0 +1,166 @@ +#!/usr/bin/Rscript +getwd() +setwd("~/git/mosaic_2020/") +getwd() +############################################################ +# TASK: boxplots at T1 +# FIXME: currently not rendering, problem with NAs for stats? +############################################################ +my_samples = "npa_sam_serum" +#============= +# Input +#============= +#source("data_extraction_formatting_non_asthmatics.R") +source("plot_data_na.R") + +# check: adult variable and age variable discrepancy! +metadata_all$mosaic[metadata_all$adult==1 & metadata_all$age<=18] + +#============= +# Output: +#============= +outfile_bp = paste0("boxplots_linear_NA_", my_samples, ".pdf") +output_boxplot = paste0(outdir_plots, outfile_bp); output_boxplot + +#=============================== +# data assignment for plots +#================================ +#----------- +# npa +#----------- +##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) +#head(lf_fp_npa$value[lf_fp_npa$mediator == "vitd"]) +#lf_fp_npa = lf_fp_npa[!lf_fp_npa$mediator == "vitd",] + +#----------- +# sam +#----------- +##wf_fp_sam = samm_wf[samm_wf$flustat == 1,] +#lf_fp_sam = sam_lf[sam_lf$flustat == 1,] +#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) +#head(lf_fp_sam$value[lf_fp_sam$mediator == "vitd"]) +#lf_fp_sam = lf_fp_sam[!lf_fp_sam$mediator == "vitd",] + +#----------- +# serum +#----------- +##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 = "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 + +#======================================================================= +# SAM +#======================================================================= +if (is.factor(lf_fp_sam$timepoint) && is.factor(lf_fp_sam$timepoint)){ + cat ("PASS: required groups are factors") +} + +#------------------------------------------ +title_sam_linear = "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 + +#======================================================================= +# 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 = "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 + +#========================================================================== +dev.off() +############################################################################ diff --git a/boxplot_log_na.R b/boxplot_log_na.R new file mode 100755 index 0000000..7eff01c --- /dev/null +++ b/boxplot_log_na.R @@ -0,0 +1,170 @@ +#!/usr/bin/Rscript +getwd() +setwd("~/git/mosaic_2020/") +getwd() +############################################################ +# TASK: boxplots at T1 +# FIXME: currently not rendering, problem with NAs for stats? +############################################################ +my_samples = "npa_sam_serum" +#============= +# Input +#============= +#source("data_extraction_formatting_non_asthmatics.R") +source("plot_data_na.R") + +# check: adult variable and age variable discrepancy! +metadata_all$mosaic[metadata_all$adult==1 & metadata_all$age<=18] + +#============= +# Output: +#============= +outfile_bp_log = paste0("boxplots_log_NA_", my_samples, ".pdf") +output_boxplot_log = paste0(outdir_plots, outfile_bp_log); output_boxplot_log + +#=============================== +# data assignment for plots +#================================ +#----------- +# npa +#----------- +#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) +head(lf_fp_npa$value[lf_fp_npa$mediator == "vitd"]) +lf_fp_npa = lf_fp_npa[!lf_fp_npa$mediator == "vitd",] + +#----------- +# sam +#----------- +#wf_fp_sam = samm_wf[samm_wf$flustat == 1,] +lf_fp_sam = sam_lf[sam_lf$flustat == 1,] +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) +head(lf_fp_sam$value[lf_fp_sam$mediator == "vitd"]) +lf_fp_sam = lf_fp_sam[!lf_fp_sam$mediator == "vitd",] + +#----------- +# serum +#----------- +#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_log) +pdf(output_boxplot_log, 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_log = "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_log = "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_log = "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() +############################################################################