added log bpxplots i.e boxplot_log.R
This commit is contained in:
parent
7946d8cf72
commit
d854f8f750
1 changed files with 169 additions and 0 deletions
169
boxplot_log.R
Normal file
169
boxplot_log.R
Normal file
|
@ -0,0 +1,169 @@
|
|||
#!/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.R")
|
||||
|
||||
# check: adult variable and age variable discrepancy!
|
||||
metadata_all$mosaic[metadata_all$adult==1 & metadata_all$age<=18]
|
||||
|
||||
#=============
|
||||
# Output:
|
||||
#=============
|
||||
outfile_bp = paste0("boxplots_log_", 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_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()
|
||||
############################################################################
|
Loading…
Add table
Add a link
Reference in a new issue