various heat-bar/position tile faff

This commit is contained in:
Tanushree Tunstall 2022-08-09 18:15:54 +01:00
parent 94454d6fba
commit 5cbaef3d36
4 changed files with 140 additions and 48 deletions

View file

@ -2,7 +2,7 @@
# 1b: Define function: coloured barplot by subgroup # 1b: Define function: coloured barplot by subgroup
# LINK: https://stackoverflow.com/questions/49818271/stacked-barplot-with-colour-gradients-for-each-bar # LINK: https://stackoverflow.com/questions/49818271/stacked-barplot-with-colour-gradients-for-each-bar
######################################################### #########################################################
source("~/git/LSHTM_analysis/scripts/functions/generate_distance_colour_map.R") #source("~/git/LSHTM_analysis/scripts/functions/generate_distance_colour_map.R")
ColourPalleteMulti = function(df, group, subgroup){ ColourPalleteMulti = function(df, group, subgroup){
@ -121,16 +121,16 @@ bp_stability_hmap <- function(plotdf = merged_df3
, axis.title.y = element_text(size = my_yaxts ) , axis.title.y = element_text(size = my_yaxts )
, plot.title = element_text(size = my_pts , plot.title = element_text(size = my_pts
, hjust = 0.5)) + , hjust = 0.5)) +
labs(title = p_title
, x = my_xlab
, y = my_ylab),
geom_tile(aes(, tpos0 # heat-mapped distance tiles along the bot geom_tile(aes(, tpos0 # heat-mapped distance tiles along the bot
, width = tW0 , width = tW0
, height = tH0) , height = tH0)
, fill = plotdf$ligD_colours , fill = plotdf$ligD_colours
, colour = plotdf$ligD_colours , colour = plotdf$ligD_colours
, linetype = "blank") + , linetype = "blank"), #end of distance-heat-bar
labs(title = p_title
, x = my_xlab
, y = my_ylab),
generate_distance_legend(plotdf), generate_distance_legend(plotdf),
ncol = 2, ncol = 2,
#align = "hv", #align = "hv",

View file

@ -171,20 +171,18 @@ LogoPlotCustomH <- function(plot_df
, seq_type = "aa") + , seq_type = "aa") +
#ylab("my custom height") + #ylab("my custom height") +
theme( axis.ticks.x = element_blank() theme( axis.ticks.x = element_blank()
, axis.ticks.length = unit(0, "pt")
, axis.title.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 # , axis.text.x = element_blank() # turn this off and the below on if you want to visually
# verify positions. # verify positions.
# , axis.text.x = element_text(size = x_ats , axis.text.x = element_text(size = x_ats
# , angle = x_tangle , angle = x_tangle
# , hjust = 1 , colour = xfont_bgc
# , vjust = 0.4 , vjust = 0.4
# , colour = xfont_bgc , margin = margin(t=-8,r=0,b=0,l=0, unit="mm")
# , margin = margin(b=0) )
# )
, axis.text.y = element_text(size = y_ats , axis.text.y = element_text(size = y_ats
, angle = y_tangle , angle = y_tangle
, hjust = 1
, vjust = 0
, colour = yfont_bgc) , colour = yfont_bgc)
, axis.title.y = element_text(size = y_tts , axis.title.y = element_text(size = y_tts
, colour = ytt_col) , colour = ytt_col)
@ -195,10 +193,11 @@ LogoPlotCustomH <- function(plot_df
, legend.position = leg_pos , legend.position = leg_pos
, legend.direction = leg_dir , legend.direction = leg_dir
, plot.background = element_rect(fill = theme_bgc) #, plot.background = element_blank()
, plot.margin = margin(b=0) , plot.margin = margin(b=0)
, panel.grid=element_blank() , panel.grid=element_blank()
, panel.background = element_rect(fill = theme_bgc) , plot.background = element_rect(fill = theme_bgc, colour=NA)
, panel.background = element_rect(fill = "transparent", colour=NA)
)+ )+
@ -220,15 +219,17 @@ LogoPlotCustomH <- function(plot_df
) )
) + ) +
geom_tile() + geom_tile() +
theme(axis.text.x = element_text(size = x_ats theme(
, angle = x_tangle axis.text.x = element_blank()
, hjust = 1 # axis.text.x = element_text(size = x_ats
, vjust = 0.4 # , angle = x_tangle
, colour = xfont_bgc) # , hjust = 1
# , vjust = 0.4
# , colour = xfont_bgc)
, axis.text.y = element_blank() , axis.text.y = element_blank()
, axis.ticks.y = element_blank() , axis.ticks.y = element_blank()
, axis.title.x = element_text(size = x_tts , axis.ticks.x = element_blank()
, colour = xtt_col) , axis.title.x = element_blank()
, axis.title.y = element_text(size = y_tts , axis.title.y = element_text(size = y_tts
, colour = ytt_col) , colour = ytt_col)
, legend.title = element_text(size = leg_tts , legend.title = element_text(size = leg_tts
@ -237,16 +238,21 @@ LogoPlotCustomH <- function(plot_df
, legend.position = leg_pos , legend.position = leg_pos
, legend.direction = leg_dir , legend.direction = leg_dir
, plot.background = element_rect(fill = theme_bgc) #, plot.background = element_blank()
, plot.margin = margin(t=0) , plot.margin = margin(t=0,b=0)
, panel.grid=element_blank() , panel.grid=element_blank()
, panel.background = element_rect(fill = theme_bgc) , plot.background = element_rect(fill = theme_bgc, colour=NA)
, panel.background = element_rect(fill = "transparent", colour=NA)
#, panel.background = element_rect(fill = theme_bgc)
#, panel.background = element_blank()
) + ) +
scale_x_discrete(x_lab, labels=factor(unique_colour_map$position)) + #scale_x_discrete(x_lab, labels=factor(unique_colour_map$position)) +
scale_color_manual(values=unique_colour_map$ligD_colours) + scale_color_manual(values=unique_colour_map$ligD_colours) +
scale_fill_manual(values=unique_colour_map$ligD_colours) + scale_fill_manual(values=unique_colour_map$ligD_colours) +
labs(y = NULL), labs(y = NULL), NULL,
ncol=1, align='v', rel_heights = c(8/10,1/10) position_annotation(plot_df, bg=theme_bgc),
ncol=1, align='v', rel_heights = c(16,1,-0.1, 1)
) )
} }
#LogoPlotCustomH(merged_df3) #LogoPlotCustomH(small_df3)

View file

@ -0,0 +1,27 @@
#minimal example
, tpos0 = 0 # 0 is a magic number that does my sensible default
, tW0 = 1
, tH0 = 0.3
plot_df = generate_distance_colour_map(plot_df, yvar_colname = stability_colname, debug=TRUE)
cowplot::plot_grid(
your_working_ggpot_statement + geom_tile(aes(, tpos0 # heat-mapped distance tiles along the bot
, width = tW0
, height = tH0)
, fill = plotdf$ligD_colours
, colour = plotdf$ligD_colours
, linetype = "blank") +
,
generate_distance_legend(plot_df, yvar_colname = stability_colname)
ncol = 2,
#align = "hv",
rel_widths = c(9/10, 0.4/10)
)

View file

@ -0,0 +1,59 @@
# position_annotation takes a Data Frame (df) and returns a ggplot object.
#
# This plots position tiles for the (up to) three ligands as well as drug
position_annotation=function(plot_df, bg="transparent"){
x_ats = 12
x_tangle = 90
x_tts = 20
y_tts = 23
xtt_col = "black"
ytt_col = "black"
leg_dir = "horizontal"
leg_ts = 15
leg_tts = 16
leg_pos = "none"
#plot_df = generate_distance_colour_map(plot_df, debug=TRUE)
ggplot(plot_df,
aes(x=factor(position), # THIS STUPID FUCKING FACTOR THING
)
) +
geom_tile(aes(y=0, fill= bg_all, colour = bg_all)
) +
geom_tile(aes(y=1, fill= col_bg1, colour = col_bg1)
) +
geom_tile(aes(y=2, fill= col_bg2, colour = col_bg2)
) +
geom_tile(aes(y=3, fill= col_bg3, colour = col_bg3)
) +
scale_x_discrete("Position", labels=factor(plot_df$position)) +
scale_color_manual(values = c(
"brown"="brown",
"purple"="purple",
"transparent"="transparent",
"blue"="blue", "cyan"="cyan",
"cornflowerblue"="cornflowerblue"
),
expand=c(0,0)
) +
scale_fill_manual(values = c(
"brown"="brown",
"purple"="purple",
"transparent"="transparent",
"blue"="blue",
"cyan"="cyan",
"cornflowerblue"="cornflowerblue"
),
expand=c(0,0)
) +
#scale_x_continuous(expand=c(0,0)) +
#scale_y_continuous(expand=c(0,0)) +
theme_nothing() +
theme(plot.background = element_rect(fill = bg, colour=NA),
plot.margin = margin(t=0,b=0)) +
labs(x = NULL, y = NULL)
}