config: add tile stuff for all targets. Other functions: many rewrites!

This commit is contained in:
Tanushree Tunstall 2022-08-15 16:29:38 +01:00
parent a3e5283a9b
commit 0cc7a8fcae
11 changed files with 163 additions and 200 deletions

View file

@ -49,16 +49,16 @@ LogoPlotCustomH <- function(plot_df
, y_axis_increment = 50
, x_lab = "Position"
, y_lab = "Odds Ratio"
, x_ats = 12 # text size
, x_ats = 6 # text size
, x_tangle = 90 # text angle
, y_ats = 22
, y_ats = 11
, y_tangle = 0
, x_tts = 20 # title size
, y_tts = 23
, x_tts = 10 # title size
, y_tts = 11
, 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
, leg_ts = 7 # leg text size
, leg_tts = 8 # leg title size
, tpos0 = 0 # 0 is a magic number that does my sensible default
, tW0 = 1
, tH0 = 0.3
@ -68,16 +68,16 @@ LogoPlotCustomH <- function(plot_df
#################################
# Data processing for logo plot
#################################
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)
# 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){
@ -147,7 +147,7 @@ LogoPlotCustomH <- function(plot_df
cat('\nSelected colour scheme:', my_logo_col
, "\nUsing grey theme")
theme_bgc = "grey"
theme_bgc = "white"
xfont_bgc = "black"
yfont_bgc = "black"
xtt_col = "black"
@ -179,7 +179,7 @@ LogoPlotCustomH <- function(plot_df
, angle = x_tangle
, colour = xfont_bgc
, vjust = 0.4
, margin = margin(t=-8,r=0,b=0,l=0, unit="mm")
, margin = margin(t=0,r=0,b=0,l=0, unit="mm")
)
, axis.text.y = element_text(size = y_ats
, angle = y_tangle
@ -211,47 +211,6 @@ LogoPlotCustomH <- function(plot_df
#, labels = seq(0, (y_lim), by = y_axis_increment)
, limits = c(0, y_lim)) +
labs(y=y_lab),
NULL,
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_blank()
# axis.text.x = element_text(size = x_ats
# , angle = x_tangle
# , hjust = 1
# , vjust = 0.4
# , colour = xfont_bgc)
, axis.text.y = element_blank()
, axis.ticks.y = element_blank()
, axis.ticks.x = element_blank()
, axis.title.x = element_blank()
, 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_blank()
, plot.margin = margin(t=0,b=1)
, panel.grid=element_blank()
, 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_color_manual(values=unique_colour_map$ligD_colours) +
scale_fill_manual(values=unique_colour_map$ligD_colours) +
labs(y = NULL),
NULL,
position_annotation(plot_df,
bg = theme_bgc,
aa_pos_drug=aa_pos_drug,
@ -261,7 +220,7 @@ LogoPlotCustomH <- function(plot_df
aa_pos_lig3=aa_pos_lig3
),
ncol=1, align='v', rel_heights = c(16,0,1,0,1)
ncol=1, align='v', rel_heights = c(6,1)
)
}
#LogoPlotCustomH(small_df3)