refactoring logo plots to add flame bar
This commit is contained in:
parent
f0a9eb4eec
commit
c968089cd2
4 changed files with 194 additions and 196 deletions
|
@ -46,7 +46,7 @@ LogoPlotCustomH <- function(plot_df
|
|||
, rm_empty_y = F
|
||||
, y_axis_log = F
|
||||
, log_value = log10
|
||||
, y_axis_increment = 5
|
||||
, y_axis_increment = 50
|
||||
, x_lab = "Position"
|
||||
, y_lab = "Odds Ratio"
|
||||
, x_ats = 12 # text size
|
||||
|
@ -68,16 +68,24 @@ LogoPlotCustomH <- function(plot_df
|
|||
#################################
|
||||
# Data processing for logo plot
|
||||
#################################
|
||||
plot_df = generate_distance_colour_map(plot_df, yvar_colname = y_axis_colname, debug=TRUE)
|
||||
plot_df = generate_distance_colour_map(plot_df, debug=TRUE)
|
||||
|
||||
unique_colour_map = unique(plot_df[,c("position","ligD_colours")])
|
||||
unique_colour_map = unique_colour_map[order(unique_colour_map$position), ]
|
||||
rownames(unique_colour_map) = unique_colour_map$position
|
||||
|
||||
unique_colour_map2 = unique_colour_map
|
||||
unique_colour_map2$position=as.factor(unique_colour_map2$position)
|
||||
unique_colour_map2$ligD_colours = as.factor(unique_colour_map2$ligD_colours)
|
||||
|
||||
|
||||
|
||||
if (rm_empty_y){
|
||||
plot_df = plot_df[!is.na(plot_df[y_axis_colname]),]
|
||||
cat("\nRemoving empty positions...\n")
|
||||
}else{
|
||||
plot_df = plot_df
|
||||
}
|
||||
|
||||
y_max = max(plot_df['or_mychisq'], na.rm = T)
|
||||
y_max = max(plot_df[[y_axis_colname]], na.rm = T)
|
||||
cat("\nRemoving y scale incremenet:", y_axis_increment)
|
||||
y_lim = round_any(y_max, y_axis_increment, f = ceiling)
|
||||
|
||||
|
@ -155,50 +163,90 @@ LogoPlotCustomH <- function(plot_df
|
|||
y_lab = paste("Log", y_lab)
|
||||
}
|
||||
}
|
||||
ggseqlogo(logo_dfP_wf
|
||||
, method = "custom"
|
||||
, col_scheme = my_logo_col
|
||||
, seq_type = "aa") +
|
||||
#ylab("my custom height") +
|
||||
theme(axis.text.x = element_text(size = x_ats
|
||||
, angle = x_tangle
|
||||
, hjust = 1
|
||||
, vjust = 0.4
|
||||
, colour = xfont_bgc)
|
||||
, axis.text.y = element_text(size = y_ats
|
||||
, angle = y_tangle
|
||||
plot_grid(
|
||||
ggplot() +
|
||||
geom_logo(logo_dfP_wf
|
||||
, method = "custom"
|
||||
, col_scheme = my_logo_col
|
||||
, seq_type = "aa") +
|
||||
#ylab("my custom height") +
|
||||
theme( axis.ticks.x = element_blank()
|
||||
, axis.title.x = element_blank()
|
||||
, axis.text.x = element_blank() # turn this off and the below on if you want to visually
|
||||
# verify positions.
|
||||
# , axis.text.x = element_text(size = x_ats
|
||||
# , angle = x_tangle
|
||||
# , hjust = 1
|
||||
# , vjust = 0.4
|
||||
# , colour = xfont_bgc
|
||||
# , margin = margin(b=0)
|
||||
# )
|
||||
, axis.text.y = element_text(size = y_ats
|
||||
, angle = y_tangle
|
||||
, hjust = 1
|
||||
, vjust = 0
|
||||
, colour = yfont_bgc)
|
||||
, axis.title.y = element_text(size = y_tts
|
||||
, colour = ytt_col)
|
||||
, legend.title = element_text(size = leg_tts
|
||||
, colour = ytt_col)
|
||||
#, legend.text = element_text(size = leg_ts)
|
||||
, legend.text = element_blank()
|
||||
|
||||
, legend.position = leg_pos
|
||||
, legend.direction = leg_dir
|
||||
, plot.background = element_rect(fill = theme_bgc)
|
||||
, plot.margin = margin(b=0)
|
||||
, panel.grid=element_blank()
|
||||
, panel.background = element_rect(fill = theme_bgc)
|
||||
|
||||
)+
|
||||
|
||||
scale_x_discrete(x_lab
|
||||
#, breaks
|
||||
, labels = position_or
|
||||
, limits = factor(1:length(position_or))) +
|
||||
|
||||
scale_y_continuous(y_lab
|
||||
, breaks = seq(0, (y_lim), by = y_axis_increment)
|
||||
#, labels = seq(0, (y_lim), by = y_axis_increment)
|
||||
, limits = c(0, y_lim)) +
|
||||
labs(y=y_lab),
|
||||
ggplot(data=unique_colour_map2, aes(
|
||||
x=factor(position), 0 # heat-mapped distance tiles along the bot
|
||||
, fill = position
|
||||
, colour = position
|
||||
, linetype = "blank"
|
||||
)
|
||||
) +
|
||||
geom_tile() +
|
||||
theme(axis.text.x = element_text(size = x_ats
|
||||
, angle = x_tangle
|
||||
, hjust = 1
|
||||
, vjust = 0
|
||||
, colour = yfont_bgc)
|
||||
, axis.title.x = element_text(size = x_tts
|
||||
, colour = xtt_col)
|
||||
, axis.title.y = element_text(size = y_tts
|
||||
, colour = ytt_col)
|
||||
, legend.title = element_text(size = leg_tts
|
||||
, colour = ytt_col)
|
||||
, legend.text = element_text(size = leg_ts)
|
||||
|
||||
, legend.position = leg_pos
|
||||
, legend.direction = leg_dir
|
||||
, plot.background = element_rect(fill = theme_bgc))+
|
||||
|
||||
scale_x_discrete(x_lab
|
||||
#, breaks
|
||||
, labels = position_or
|
||||
, limits = factor(1:length(position_or))) +
|
||||
|
||||
scale_y_continuous(y_lab
|
||||
, breaks = seq(0, (y_lim), by = y_axis_increment)
|
||||
#, labels = seq(0, (y_lim), by = y_axis_increment)
|
||||
, limits = c(0, y_lim)) +
|
||||
ylab(y_lab) +
|
||||
geom_tile(aes(plot_df$position, tpos0 # heat-mapped distance tiles along the bot
|
||||
, width = tW0
|
||||
, height = tH0)
|
||||
, fill = plot_df$ligD_colours
|
||||
, colour = plot_df$ligD_colours
|
||||
, linetype = "blank")
|
||||
#LogoPlot = p0 + ylab(y_lab)
|
||||
#return(LogoPlot)
|
||||
|
||||
}
|
||||
, vjust = 0.4
|
||||
, colour = xfont_bgc)
|
||||
, axis.text.y = element_blank()
|
||||
, axis.ticks.y = element_blank()
|
||||
, axis.title.x = element_text(size = x_tts
|
||||
, colour = xtt_col)
|
||||
, axis.title.y = element_text(size = y_tts
|
||||
, colour = ytt_col)
|
||||
, legend.title = element_text(size = leg_tts
|
||||
, colour = ytt_col)
|
||||
, legend.text = element_text(size = leg_ts)
|
||||
|
||||
, legend.position = leg_pos
|
||||
, legend.direction = leg_dir
|
||||
, plot.background = element_rect(fill = theme_bgc)
|
||||
, plot.margin = margin(t=0)
|
||||
, panel.grid=element_blank()
|
||||
, panel.background = element_rect(fill = theme_bgc)
|
||||
) +
|
||||
scale_x_discrete(x_lab, labels=factor(unique_colour_map$position)) +
|
||||
scale_color_manual(values=unique_colour_map$ligD_colours) +
|
||||
scale_fill_manual(values=unique_colour_map$ligD_colours) +
|
||||
labs(y = NULL),
|
||||
ncol=1, align='v', rel_heights = c(8/10,1/10)
|
||||
)
|
||||
}
|
||||
#LogoPlotCustomH(merged_df3)
|
Loading…
Add table
Add a link
Reference in a new issue