From 1244581cddbd8cd60cbf4065b3a81ce3a63d8357 Mon Sep 17 00:00:00 2001 From: Tanushree Tunstall Date: Sun, 16 Jan 2022 13:31:32 +0000 Subject: [PATCH] just added some minor tweaks for the logo plots with OR --- scripts/functions/logoP.R | 45 +++++++++++++++++++++++----- scripts/functions/tests/test_logoP.R | 6 ++-- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/scripts/functions/logoP.R b/scripts/functions/logoP.R index 1a18282..d25fd24 100644 --- a/scripts/functions/logoP.R +++ b/scripts/functions/logoP.R @@ -49,6 +49,7 @@ LogoPlotCustomH <- function(plot_df , symbol_colname = "mutant_type" , y_axis_log = F , log_value = log10 + , y_scale_increment = 5 , rm_empty_pos = F , my_logo_col = "chemistry" , x_lab = "Position" @@ -80,6 +81,11 @@ LogoPlotCustomH <- function(plot_df }else{ plot_df = plot_df } + + y_max = max(plot_df['or_mychisq'], na.rm = T) + cat("\nRemoving y scale incremenet:", y_scale_increment) + y_lim = round_any(y_max, y_scale_increment, f = ceiling) + #------------------- # logo data: LogOR #------------------- @@ -91,6 +97,13 @@ LogoPlotCustomH <- function(plot_df logo_df_plot = logo_df[, c(x_axis_colname, symbol_colname, log_colname)] logo_dfP_wf = as.matrix(logo_df_plot %>% spread(x_axis_colname, log_colname, fill = 0.0)) + #!!! For consideration: to add y_axis 'breaks' and 'limits' !!! + #y_max = max(plot_df[[log_colname]], na.rm = T) + #y_scale_increment = + #cat("\nRemoving y scale incremenet:", y_scale_increment) + + #y_lim = round_any(y_max, y_scale_increment, f = ceiling) + } else { #------------------- @@ -138,7 +151,7 @@ LogoPlotCustomH <- function(plot_df ytt_col = "black" } - LogoPlot = ggseqlogo(logo_dfP_wf + p0 = ggseqlogo(logo_dfP_wf , method = "custom" , col_scheme = my_logo_col , seq_type = "aa") + @@ -157,21 +170,37 @@ LogoPlotCustomH <- function(plot_df , colour = xtt_col) , axis.title.y = element_text(size = y_tts , colour = ytt_col) - , legend.title = element_text(size = y_tts + , legend.title = element_text(size = leg_tts , colour = ytt_col) - , legend.text = element_text(size = leg_ts) + , legend.text = element_text(size = leg_ts) , legend.position = leg_pos , legend.direction = leg_dir - , plot.background = element_rect(fill = theme_bgc) - , legend.text = element_text(size = leg_ts) - , legend.title = element_text(size = leg_tts))+ + , plot.background = element_rect(fill = theme_bgc))+ + scale_x_discrete(x_lab #, breaks , labels = position_or - , limits = factor(1:length(position_or))) + - ylab(y_lab) + , limits = factor(1:length(position_or))) + LogoPlot = p0 + scale_y_continuous(y_lab + , breaks = seq(0, (y_lim), by = y_scale_increment) + #, labels = seq(0, (y_lim), by = y_scale_increment) + , limits = c(0, y_lim)) + if (y_axis_log){ + + if (grepl("Log", y_lab)){ + y_lab = y_lab + + }else{ + y_lab = paste("Log", y_lab) + } + + LogoPlot = p0 + ylab(y_lab) + + } + + return(LogoPlot) } \ No newline at end of file diff --git a/scripts/functions/tests/test_logoP.R b/scripts/functions/tests/test_logoP.R index 57b9ac0..006c43e 100644 --- a/scripts/functions/tests/test_logoP.R +++ b/scripts/functions/tests/test_logoP.R @@ -7,9 +7,11 @@ LogoPlotCustomH (plot_df = merged_df3 , x_axis_colname = "position" , y_axis_colname = "or_mychisq" , symbol_colname = "mutant_type" - , y_axis_log = T + , y_axis_log = F , log_value = log10 - , rm_empty_pos = T + , y_scale_increment = 5 + + , rm_empty_pos = F , my_logo_col = 'chemistry' , x_lab = "Position" , y_lab = "Odds Ratio"