adding legend forlogo plot
This commit is contained in:
parent
426a5cb0b5
commit
3b7cea3c47
4 changed files with 60 additions and 55 deletions
|
@ -32,13 +32,15 @@
|
|||
#==================
|
||||
# NOTE: my_logo_col
|
||||
# Can be one of these: 'chemistry', 'hydrophobicity', 'clustalx', 'taylor'
|
||||
# if 'chemistry' or 'hydrophobicity' --> then bg is grey with black font
|
||||
# if 'clustalx'or 'taylor' --> then bg is black with white font
|
||||
# if 'chemistry' or 'hydrophobicity' --> then bg is grey with black font (x, y and labels)
|
||||
# if 'clustalx'or 'taylor' --> then bg is black with white font (x, y and labels)
|
||||
#, theme_bgc =
|
||||
#, xfont_bgc =
|
||||
#, yfont_bgc =
|
||||
#, xtt_col =
|
||||
#, ytt_col =
|
||||
|
||||
# ADD legend for hydrophobicity
|
||||
# ADD legend for hydrophobicity: done
|
||||
# ADD option to remove empty positions
|
||||
|
||||
LogoPlotCustomH <- function(plotdf
|
||||
|
@ -57,10 +59,12 @@ LogoPlotCustomH <- function(plotdf
|
|||
#, yfont_bgc
|
||||
, y_ats = 22
|
||||
, y_tangle = 0
|
||||
, x_tts = 25 # title size
|
||||
, y_tts = 20
|
||||
, leg_pos = "none"
|
||||
#, leg_pos = c(0.8, 0.9)
|
||||
, x_tts = 20 # title size
|
||||
, y_tts = 23
|
||||
#, xtt_col =
|
||||
#, ytt_col =
|
||||
, leg_pos = "none" # can be top, left, right and bottom or c(0.8, 0.9)
|
||||
, leg_dir = "horizontal" #can be vertical or horizontal
|
||||
, leg_ts = 15 # leg text size
|
||||
, leg_tts = 16 # leg title size
|
||||
)
|
||||
|
@ -72,13 +76,8 @@ LogoPlotCustomH <- function(plotdf
|
|||
|
||||
logo_df = plotdf
|
||||
|
||||
if (y_axis_log){
|
||||
log_colname = paste0("log_", y_axis_colname)
|
||||
logo_df[log_colname] = log_value(logo_df[y_axis_colname])
|
||||
}
|
||||
logo_data_plot2 = logo_df[, c(x_axis_colname, symbol_colname, y_axis_colname)]
|
||||
|
||||
logo_data_plot2 = logo_df[, c(x_axis_colname, symbol_colname, y_axis_colname, log_colname)]
|
||||
|
||||
#==================
|
||||
# logo data: OR
|
||||
#==================
|
||||
|
@ -99,21 +98,26 @@ LogoPlotCustomH <- function(plotdf
|
|||
#==================
|
||||
# logo data: logOR
|
||||
#==================
|
||||
logo_data_plot2_logor = logo_df[, c(x_axis_colname, symbol_colname, log_colname)]
|
||||
|
||||
wide_df2_logor = as.matrix(logo_data_plot2_logor %>% spread(x_axis_colname, log_colname, fill = 0.0))
|
||||
class(wide_df2_logor)
|
||||
|
||||
rownames(wide_df2_logor) = wide_df2_logor[,1]
|
||||
dim(wide_df2_logor)
|
||||
|
||||
#wide_df2_logor = subset(wide_df_logor, select = -c(1) )
|
||||
wide_df2_logor = wide_df2_logor[,-1]
|
||||
str(wide_df2_logor)
|
||||
|
||||
colnames(wide_df2_logor)
|
||||
position_logor = as.numeric(colnames(wide_df2_logor))
|
||||
if (y_axis_log){
|
||||
|
||||
log_colname = paste0("log_", y_axis_colname)
|
||||
logo_df[log_colname] = log_value(logo_df[y_axis_colname])
|
||||
logo_data_plot2 = logo_df[, c(x_axis_colname, symbol_colname, y_axis_colname,log_colname )]
|
||||
|
||||
logo_data_plot2_logor = logo_df[, c(x_axis_colname, symbol_colname, log_colname)]
|
||||
|
||||
wide_df2_logor = as.matrix(logo_data_plot2_logor %>% spread(x_axis_colname, log_colname, fill = 0.0))
|
||||
class(wide_df2_logor)
|
||||
|
||||
rownames(wide_df2_logor) = wide_df2_logor[,1]
|
||||
dim(wide_df2_logor)
|
||||
|
||||
wide_df2_logor = wide_df2_logor[,-1]
|
||||
str(wide_df2_logor)
|
||||
|
||||
colnames(wide_df2_logor)
|
||||
position_logor = as.numeric(colnames(wide_df2_logor))
|
||||
}
|
||||
|
||||
######################################
|
||||
# Generating plots with given y_axis
|
||||
|
@ -123,10 +127,11 @@ LogoPlotCustomH <- function(plotdf
|
|||
if (my_logo_col %in% c('clustalx','taylor')) {
|
||||
cat("\nSelected colour scheme:", my_logo_col
|
||||
, "\nUsing black theme\n")
|
||||
theme_bgc = "black"
|
||||
theme_bgc = "black"
|
||||
xfont_bgc = "white"
|
||||
yfont_bgc = "black"
|
||||
|
||||
yfont_bgc = "white"
|
||||
xtt_col = "white"
|
||||
ytt_col = "white"
|
||||
}
|
||||
|
||||
if (my_logo_col %in% c('chemistry', 'hydrophobicity')) {
|
||||
|
@ -135,7 +140,8 @@ LogoPlotCustomH <- function(plotdf
|
|||
theme_bgc = "grey"
|
||||
xfont_bgc = "black"
|
||||
yfont_bgc = "black"
|
||||
|
||||
xtt_col = "black"
|
||||
ytt_col = "black"
|
||||
}
|
||||
|
||||
LogoPlot = ggseqlogo(wide_df2_or
|
||||
|
@ -152,10 +158,12 @@ LogoPlotCustomH <- function(plotdf
|
|||
, hjust = 1
|
||||
, vjust = 0
|
||||
, colour = yfont_bgc)
|
||||
, axis.title.y = element_text(size = x_tts)
|
||||
, axis.title.x = element_text(size = y_tts)
|
||||
#, legend.position = "bottom") +
|
||||
, axis.title.x = element_text(size = x_tts
|
||||
, colour = xtt_col)
|
||||
, axis.title.y = element_text(size = y_tts
|
||||
, colour = ytt_col)
|
||||
, 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))+
|
||||
|
@ -165,7 +173,6 @@ LogoPlotCustomH <- function(plotdf
|
|||
, limits = factor(1:length(position_or))) +
|
||||
ylab(y_lab)
|
||||
|
||||
#print(logo_or)
|
||||
return(LogoPlot)
|
||||
|
||||
}
|
||||
|
|
|
@ -7,21 +7,20 @@ LogoPlotCustomH (plotdf = 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
|
||||
, my_logo_col = 'hydrophobicity'
|
||||
#, theme_bgc
|
||||
# , xfont_bgc
|
||||
# , yfont_bgc
|
||||
, my_logo_col = 'chemistry'
|
||||
, x_lab = "Position"
|
||||
, y_lab = "Odds Ratio"
|
||||
, x_ats = 12 # text size
|
||||
, x_tangle = 90 # text angle
|
||||
, y_ats = 22
|
||||
, y_tangle = 0
|
||||
, x_tts = 25 # title size
|
||||
, y_tts = 20
|
||||
, leg_pos = "none"
|
||||
, x_tts = 20 # title size
|
||||
, y_tts = 23
|
||||
#, leg_pos = c(0.05,-0.12)
|
||||
, leg_pos = "top"
|
||||
, leg_dir = "horizontal"
|
||||
, leg_ts = 15 # leg text size
|
||||
, leg_tts = 16 # leg title size
|
||||
)
|
||||
|
|
|
@ -69,25 +69,25 @@ svg(plot_logo_or, width = 30 , height = 6)
|
|||
logo_or = ggseqlogo(wide_df_or
|
||||
, method = "custom"
|
||||
, seq_type = "aa") + ylab("my custom height") +
|
||||
theme( axis.text.x = element_text(size = 12
|
||||
, angle = 90
|
||||
theme( axis.text.x = element_text(size = x_ats
|
||||
, angle = x_tangle
|
||||
, hjust = 1
|
||||
, vjust = 0.4)
|
||||
, axis.text.y = element_text(size = 22
|
||||
, angle = 0
|
||||
, axis.text.y = element_text(size = y_ats
|
||||
, angle = y_tangle
|
||||
, hjust = 1
|
||||
, vjust = 0)
|
||||
, axis.title.y = element_text(size = 25)
|
||||
, axis.title.x = element_text(size = 20)
|
||||
, axis.title.y = element_text(size = x_tts)
|
||||
, axis.title.x = element_text(size = y_tts)
|
||||
#, legend.position = "bottom") +
|
||||
, legend.position = "none")+
|
||||
#, legend.text = element_text(size = 15)
|
||||
#, legend.title = element_text(size = 15))+
|
||||
scale_x_discrete("Position"
|
||||
, legend.position = leg_pos)+
|
||||
#, legend.text = element_text(size = leg_ts)
|
||||
#, legend.title = element_text(size = leg_tts))+
|
||||
scale_x_discrete(x_lab
|
||||
#, breaks
|
||||
, labels = position_or
|
||||
, limits = factor(1:length(position_or))) +
|
||||
ylab("Odds Ratio")
|
||||
ylab(y_lab)
|
||||
|
||||
print(logo_or)
|
||||
#dev.off()
|
||||
|
|
|
@ -30,7 +30,6 @@ wc -l TEST2.csv
|
|||
sed -E 's/>.*//g' TEST2.csv | sed '/^$/d' > TEST3.csv
|
||||
wc -l TEST3.csv
|
||||
|
||||
|
||||
# doubles the no as it adds the mut info
|
||||
python3 mutate.py -v -o /home/tanu/git/LSHTM_analysis/scripts/plotting/scratch_plots/TEST.csv /home/tanu/git/LSHTM_analysis/scripts/plotting/scratch_plots/pnca_mut_map.csv /home/tanu/git/Data/pyrazinamide/input/pnca.fasta
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue