diff --git a/boxplot_stat_all.R b/boxplot_stat_all.R old mode 100644 new mode 100755 index b271c1d..5288fb6 --- a/boxplot_stat_all.R +++ b/boxplot_stat_all.R @@ -3,19 +3,31 @@ getwd() setwd("~/git/mosaic_2020/") getwd() ############################################################### +#============= +# Input +#============= source("boxplot_stat_function.R") source("plot_data.R") + #============= -# Output: +# Output #============= outfile_bp = paste0("boxplots_stats_all", ".pdf") output_boxplot_stats = paste0(outdir_plots, outfile_bp); output_boxplot_stats pdf(output_boxplot_stats, width=22, height=16) - -#=========================== +############################################################### +#=============================== +# data assignment for plots +#=============================== +#------------- # NPA -#=========================== +#------------- my_sample_npa = "NPA" +fp_npa = length(unique(lf_fp_npa$mosaic)); fp_npa + +cat("\nPlotting boxplots with stats for:", my_sample_npa + , "\n========================================================\n") + plots_npa = doMyPlots(lf_fp_npa) npa_plot = ggpubr::ggarrange(plotlist = plots_npa , align = "hv" @@ -24,36 +36,64 @@ npa_plot = ggpubr::ggarrange(plotlist = plots_npa , common.legend = T) #npa_plot npa_plot_annot = annotate_figure(npa_plot - , top = text_grob(my_sample_npa, color = "blue", face = "bold", size = 14) - , bottom = text_grob("Mosaic data\nFlu positive adults (n=133)" + , top = text_grob(my_sample_npa + , color = "blue" + , face = "bold" + , size = 14) + , bottom = text_grob(paste0("Mosaic data\nFlu positive adults (n=", fp_npa, ")") , color = "blue" - , hjust = 1, x = 0.98, face = "italic", size = 10) - , left = text_grob("Levels (pg/ml)", color = "black", rot = 90, size = 18)) + , hjust = 1 + , x = 0.98 + , face = "italic" + , size = 10) + , left = text_grob("Levels (pg/ml)" + , color = "black" + , rot = 90 + , size = 18)) npa_plot_annot #dev.off() -#=========================== +#------------- # SAM -#=========================== -my_sample_sam = "SAM" -plots_sam = doMyPlots(lf_fp_sam) -sam_plot = ggpubr::ggarrange(plotlist = plots_sam - , align = "hv" - , ncol = 7 - , nrow = 5 - , common.legend = T) +#------------- +#my_sample_sam = "SAM" +#fp_sam = length(unique(lf_fp_sam$mosaic)); fp_sam + +#cat("\nPlotting boxplots with stats for:", my_sample_sam +# , "\n========================================================\n") + +#plots_sam = doMyPlots(lf_fp_sam) +#sam_plot = ggpubr::ggarrange(plotlist = plots_sam +# , align = "hv" +# , ncol = 7 +# , nrow = 5 +# , common.legend = T) #sam_plot -sam_plot_annot = annotate_figure(sam_plot - , top = text_grob(my_sample_sam, color = "blue", face = "bold", size = 14) - , bottom = text_grob("Mosaic data\nFlu positive adults (n=133)" - , color = "blue" - , hjust = 1, x = 0.98, face = "italic", size = 10) - , left = text_grob("Levels (pg/ml)", color = "black", rot = 90, size = 18)) -sam_plot_annot +#sam_plot_annot = annotate_figure(sam_plot +# , top = text_grob(my_sample_sam +# , color = "blue" +# , face = "bold" +# , size = 14) +# , bottom = text_grob(paste0("Mosaic data\nFlu positive adults (n=", fp_sam, ")") +# , color = "blue" +# , hjust = 1 +# , x = 0.98 +# , face = "italic" +# , size = 10) +# , left = text_grob("Levels (pg/ml)" +# , color = "black" +# , rot = 90 +# , size = 18)) +#sam_plot_annot #dev.off() -#=========================== +#------------- # SERUM -#=========================== +#------------- my_sample_serum = "serum" +fp_serum = length(unique(lf_fp_serum$mosaic)); fp_serum + +cat("\nPlotting boxplots with stats for:", my_sample_serum + , "\n========================================================\n") + plots_serum = doMyPlots(lf_fp_serum) serum_plot = ggpubr::ggarrange(plotlist = plots_serum , align = "hv" @@ -62,10 +102,20 @@ serum_plot = ggpubr::ggarrange(plotlist = plots_serum , common.legend = T) #serum_plot serum_plot_annot = annotate_figure(serum_plot - , top = text_grob(my_sample_serum, color = "blue", face = "bold", size = 14) - , bottom = text_grob("Mosaic data\nFlu positive adults (n=133)" + , top = text_grob(my_sample_serum + , color = "blue" + , face = "bold" + , size = 14) + , bottom = text_grob(paste0("Mosaic data\nFlu positive adults (n=", fp_serum, ")") , color = "blue" - , hjust = 1, x = 0.98, face = "italic", size = 10) - , left = text_grob("Levels (pg/ml)", color = "black", rot = 90, size = 18)) + , hjust = 1 + , x = 0.98 + , face = "italic" + , size = 10) + , left = text_grob("Levels (pg/ml)" + , color = "black" + , rot = 90 + , size = 18)) serum_plot_annot dev.off() +############################################################### diff --git a/boxplot_stat_function.R b/boxplot_stat_function.R old mode 100644 new mode 100755 diff --git a/boxplot_stat_test.R b/boxplot_stat_function_test.R old mode 100644 new mode 100755 similarity index 61% rename from boxplot_stat_test.R rename to boxplot_stat_function_test.R index 4866521..f9a86fd --- a/boxplot_stat_test.R +++ b/boxplot_stat_function_test.R @@ -11,6 +11,7 @@ source("plot_data.R") my_sample_name = "SAM" to_remove = c("ifna2a", "il29") lf_fp_sam2 = lf_fp_sam[!lf_fp_sam$mediator%in%to_remove,] +lf_fp_sam3 = lf_fp_sam[lf_fp_sam$mediator%in%to_remove,] foo = doMyPlots(lf_fp_sam2) @@ -23,11 +24,19 @@ pdf(output_boxplot_stats, width=22, height=16) #baz=cowplot::plot_grid(plotlist=foo, align = 'hv', ncol=2, nrow=2) foo_annot = annotate_figure(foo - , top = text_grob(my_sample_name, color = "blue", face = "bold", size = 14) + , top = text_grob(my_sample_name + , color = "blue" + , face = "bold" + , size = 14) , bottom = text_grob("Mosaic data\nFlu positive adults (n=133)" , color = "blue" - , hjust = 1, x = 0.98, face = "italic", size = 10) - , left = text_grob("Levels (pg/ml)", color = "black", rot = 90, size = 18) + , hjust = 1, x = 0.98 + , face = "italic" + , size = 10) + , left = text_grob("Levels (pg/ml)" + , color = "black" + , rot = 90 + , size = 18) ) foo_annot dev.off() diff --git a/boxplot_with_stats.R b/boxplot_with_stats.R old mode 100644 new mode 100755 diff --git a/plot_data.R b/plot_data.R old mode 100644 new mode 100755 index 4df2c41..5d34538 --- a/plot_data.R +++ b/plot_data.R @@ -6,7 +6,7 @@ getwd() # TASK: boxplots at T1 # FIXME: currently not rendering, problem with NAs for stats? ############################################################ -my_samples = "npa_sam_serum" + #============= # Input #============= @@ -15,12 +15,6 @@ source("data_extraction_formatting.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_", my_samples, ".pdf") -output_boxplot = paste0(outdir_plots, outfile_bp); output_boxplot - #=============================== # data assignment for plots #================================ @@ -36,6 +30,7 @@ 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",] +table(lf_fp_npa$mediator) #----------- # sam @@ -49,6 +44,7 @@ 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",] +table(lf_fp_sam$mediator) #----------- # serum @@ -59,4 +55,5 @@ 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) +head(lf_fp_sam$value[lf_fp_serum$mediator == "vitd"]) ######################################################################## \ No newline at end of file