replaced old lineage barplot with count and diversity combined plots sourced from function
This commit is contained in:
parent
50b89cdcd7
commit
3cee341170
7 changed files with 217 additions and 366 deletions
128
scripts/plotting/lineage_basic_barplots_combined.R
Normal file
128
scripts/plotting/lineage_basic_barplots_combined.R
Normal file
|
@ -0,0 +1,128 @@
|
|||
#!/usr/bin/env Rscript
|
||||
getwd()
|
||||
setwd("~/git/LSHTM_analysis/scripts/plotting/")
|
||||
getwd()
|
||||
#########################################################
|
||||
# TASK: Basic lineage barplot showing numbers
|
||||
|
||||
# Output: Basic barplot with lineage samples and mut count
|
||||
|
||||
##########################################################
|
||||
# Installing and loading required packages
|
||||
##########################################################
|
||||
source("Header_TT.R")
|
||||
source("../functions/bp_lineage.R")
|
||||
|
||||
#===========
|
||||
# input
|
||||
#===========
|
||||
source ('get_plotting_dfs.R')
|
||||
|
||||
cat("Directories imported:"
|
||||
, "\n===================="
|
||||
, "\ndatadir:", datadir
|
||||
, "\nindir:", indir
|
||||
, "\noutdir:", outdir
|
||||
, "\nplotdir:", plotdir)
|
||||
|
||||
cat("Variables imported:"
|
||||
, "\n====================="
|
||||
, "\ndrug:", drug
|
||||
, "\ngene:", gene
|
||||
, "\ngene_match:", gene_match
|
||||
, "\nAngstrom symbol:", angstroms_symbol
|
||||
#, "\nNo. of duplicated muts:", dup_muts_nu
|
||||
, "\ndr_muts_col:", dr_muts_col
|
||||
, "\nother_muts_col:", other_muts_col
|
||||
, "\ndrtype_col:", resistance_col)
|
||||
|
||||
#=======
|
||||
# output
|
||||
#=======
|
||||
# plot 1
|
||||
basic_bp_lineage_cl = "basic_lineage_barplots_combined.svg"
|
||||
plot_basic_bp_lineage_cl = paste0(plotdir,"/", basic_bp_lineage_cl)
|
||||
plot_basic_bp_lineage_cl
|
||||
#################################################################
|
||||
#=============================
|
||||
# PLOT 1: Lineage count plot:
|
||||
# LF data
|
||||
#=============================
|
||||
#------------------------
|
||||
# Data: All lineages or
|
||||
# selected few
|
||||
#------------------------
|
||||
sel_lineages = levels(lin_lf$sel_lineages_f)[1:4]
|
||||
sel_lineages
|
||||
lin_lf_plot = lin_lf[lin_lf$sel_lineages_f%in%sel_lineages,]
|
||||
str(lin_lf_plot)
|
||||
|
||||
# drop unused factor levels
|
||||
lin_lf_plot$sel_lineages_f = factor(lin_lf_plot$sel_lineages_f)
|
||||
levels(lin_lf_plot$sel_lineages_f)
|
||||
str(lin_lf_plot)
|
||||
|
||||
#------------------------
|
||||
# plot from my function:
|
||||
#------------------------
|
||||
lin_countP = lin_count_bp(lin_lf_plot
|
||||
, x_categ = "sel_lineages_f"
|
||||
, y_count = "p_count"
|
||||
, bar_fill_categ = "count_categ"
|
||||
, display_label_col = "p_count"
|
||||
, bar_stat_stype = "identity"
|
||||
, x_lab_angle = 90
|
||||
, my_xats = 20
|
||||
, bar_col_labels = c("Mutations", "Total Samples")
|
||||
, bar_col_values = c("grey50", "gray75")
|
||||
, y_scale_percent = F # T for diversity
|
||||
, y_log10 = F
|
||||
, y_label = "Count")
|
||||
lin_countP
|
||||
#================================
|
||||
# PLOT 2: Lineage Diversity plot
|
||||
# WF data
|
||||
#================================
|
||||
#------------------------
|
||||
# Data: All lineages or
|
||||
# selected few
|
||||
#------------------------
|
||||
sel_lineages = levels(lin_wf$sel_lineages_f)[1:4]
|
||||
sel_lineages
|
||||
lin_wf_plot = lin_wf[lin_wf$sel_lineages_f%in%sel_lineages,]
|
||||
str(lin_wf_plot)
|
||||
|
||||
# drop unused factor levels
|
||||
lin_wf_plot$sel_lineages_f = factor(lin_wf_plot$sel_lineages_f)
|
||||
levels(lin_wf_plot$sel_lineages_f)
|
||||
str(lin_wf_plot)
|
||||
|
||||
#------------------------
|
||||
# plot from my function:
|
||||
#------------------------
|
||||
lin_diversityP = lin_count_bp(lin_wf_plot
|
||||
, x_categ = "sel_lineages_f"
|
||||
, y_count = "snp_diversity"
|
||||
, display_label_col = "snp_diversity_f"
|
||||
, bar_stat_stype = "identity"
|
||||
, x_lab_angle = 90
|
||||
, my_xats = 20
|
||||
, y_scale_percent = T
|
||||
, y_label = "SNP diversity")
|
||||
|
||||
lin_diversityP
|
||||
#########################################################################333
|
||||
#================================
|
||||
# Combine plots
|
||||
#================================
|
||||
|
||||
svg(plot_basic_bp_lineage_cl , width = 8, height = 15 )
|
||||
|
||||
lineage_bp_combined = cowplot::plot_grid(lin_countP, lin_diversityP
|
||||
#, labels = c("(a)", "(b)", "(c)", "(d)")
|
||||
, nrow = 2
|
||||
, labels = "AUTO"
|
||||
, label_size = 25)
|
||||
|
||||
lineage_bp_combined
|
||||
dev.off()
|
Loading…
Add table
Add a link
Reference in a new issue