added new layput for dm_om and facet_lineage plot

This commit is contained in:
Tanushree Tunstall 2020-09-17 14:01:04 +01:00
parent a5b03e53e8
commit 375cdc2068

View file

@ -146,6 +146,7 @@ check = u2[!u2%in%u]; print(check)
# lineage: labels
# from "plyr"
#==================
#{Result:No of samples in selected lineages}
table(df_lin$lineage)
df_lin$lineage_labels = mapvalues(df_lin$lineage
@ -166,6 +167,19 @@ table(df_lin$mutation_info_labels)
table(df_lin$mutation_info) == table(df_lin$mutation_info_labels)
#========================
# duet_outcome: labels
#========================
#{Result: No. of D and S mutations in selected lineages}
table(df_lin$duet_outcome)
df_lin$duet_outcome_labels = ifelse(df_lin$duet_outcome == "Destabilising", "D", "S")
table(df_lin$duet_outcome_labels)
table(df_lin$duet_outcome) == table(df_lin$duet_outcome_labels)
#=======================
# subset dr muts only
#=======================
@ -208,28 +222,37 @@ my_palette <- colorRampPalette(c(mcsm_red2, mcsm_red1, mcsm_mid, mcsm_blue1, mcs
# Plot 1: lineage dist: geom_density_ridges_gradient (allows aesthetics to vary along ridgeline, no alpha setting!)
# else same as geom_density_ridges)
# x = duet_scaled
# y = lineage_labels
# fill = duet_scaled
# NO FACET (nf)
# y = duet_outcome
# fill = duet_scaled
# Facet: Lineage
#=======================================
# output individual svg
#plot_lineage_dist_duet_nf = paste0(plotdir,"/", "lineage_dist_duet_nf.svg")
#plot_lineage_dist_duet_nf
#svg(plot_lineage_dist_duet_nf)
#plot_lineage_dist_duet_f paste0(plotdir,"/", "lineage_dist_duet_f.svg")
#plot_lineage_dist_duet_f
#svg(plot_lineage_dist_duet_f)
p1 = ggplot(df, aes(x = duet_scaled
, y = lineage_labels))+
, y = duet_outcome))+
geom_density_ridges_gradient(aes(fill = ..x..)
#, jittered_points = TRUE
, scale = 3
, size = 0.3 ) +
facet_wrap( ~lineage_labels
# , scales = "free"
# , labeller = labeller(lineage = my_labels)
) +
coord_cartesian( xlim = c(-1, 1)) +
scale_fill_gradientn(colours = my_palette, name = "DUET") +
scale_fill_gradientn(colours = my_palette
, name = "DUET"
#, breaks = c(-1, 0, 1)
#, labels = c(-1,0,1)
#, limits = c(-1,1)
) +
theme(axis.text.x = element_text(size = my_ats
, angle = 90
, hjust = 1
, vjust = 0.4)
#, axis.text.y = element_blank()
, axis.text.y = element_text(size = my_ats)
, axis.title.x = element_text(size = my_ats)
, axis.title.y = element_blank()
@ -237,18 +260,19 @@ p1 = ggplot(df, aes(x = duet_scaled
, plot.title = element_blank()
, strip.text = element_text(size = my_als)
, legend.text = element_text(size = my_als-10)
, legend.title = element_text(size = my_als-3)
, legend.position = c(0.8, 0.8)) +
#, legend.direction = "horizontal")+
#, legend.position = "top", )+
#, legend.title = element_text(size = my_als-6)
, legend.title = element_blank()
, legend.position = c(-0.08, 0.41)
#, legend.direction = "horizontal"
#, legend.position = "left"
)+
labs(x = "DUET")
p1
#p1_copy = p1 + guides(fill = guide_colourbar(label = FALSE))
#p1_copy= p1_copy + guides(size=guide_legend("Source", override.aes=list(shape=15, size = 10)))
#p1_copy
#p1_with_legend = p1 + guides(fill = guide_colourbar(label = FALSE))
#=======================================
# Plot 2: lineage dist: geom_density_ridges, allows alpha to be set
# x = duet_scaled
@ -279,14 +303,55 @@ p2 = ggplot(df, aes(x = duet_scaled
, axis.ticks.y = element_blank()
, plot.title = element_blank()
, strip.text = element_text(size = my_als)
, legend.text = element_text(size = my_als-2)
, legend.title = element_text(size = my_als-3)
, legend.text = element_text(size = my_als-4)
, legend.title = element_text(size = my_als-4)
, legend.position = c(0.8, 0.9)) +
labs(x = "DUET"
, fill = "Mutation class") # legend title
p2
#=======================================
# Plot 3: lineage dist: geom_density_ridges_gradient (allows aesthetics to vary along ridgeline, no alpha setting!)
# else same as geom_density_ridges)
# x = duet_scaled
# y = lineage_labels
# fill = duet_scaled
# NO FACET (nf)
#=======================================
# output individual svg
#plot_lineage_dist_duet_nf = paste0(plotdir,"/", "lineage_dist_duet_nf.svg")
#plot_lineage_dist_duet_nf
#svg(plot_lineage_dist_duet_nf)
p3 = ggplot(df, aes(x = duet_scaled
, y = lineage_labels))+
geom_density_ridges_gradient(aes(fill = ..x..)
#, jittered_points = TRUE
, scale = 3
, size = 0.3 ) +
coord_cartesian( xlim = c(-1, 1)) +
scale_fill_gradientn(colours = my_palette, name = "DUET") +
theme(axis.text.x = element_text(size = my_ats
, angle = 90
, hjust = 1
, vjust = 0.4)
, axis.text.y = element_text(size = my_ats)
, axis.title.x = element_text(size = my_ats)
, axis.title.y = element_blank()
, axis.ticks.y = element_blank()
, plot.title = element_blank()
, strip.text = element_text(size = my_als)
, legend.text = element_text(size = my_als-10)
, legend.title = element_text(size = my_als-3)
, legend.position = c(0.8, 0.8)) +
#, legend.direction = "horizontal")+
#, legend.position = "top")+
labs(x = "DUET")
p3
########################################################################
#==============
# combine plots
@ -307,11 +372,14 @@ plot_lineage_dist_combined_dm_om_L
svg(plot_lineage_dist_combined_dm_om_L, width = 12, height = 6)
OutPlot2 = cowplot::plot_grid(p1, p2
, labels = c("(a)", "(b)")
, rel_widths = c(0.5/2, 0.5/2)
, label_size = my_als)
, labels = c("(a)", "(b)")
#, label_x = -0.045, label_y = 0.92
#, hjust = -0.7, vjust = -0.5
#, align = "h"
, rel_widths = c(0.5/2, 0.5/2)
, label_size = my_als)
print(OutPlot2)
dev.off()
##############################################################################
##############################################################################