lf_bp2
This commit is contained in:
parent
33925dafe9
commit
d5bc1c272e
4 changed files with 193 additions and 12 deletions
|
@ -236,6 +236,19 @@ consurf_colours = c(#"0" = rgb(1.00,1.00,0.59)
|
||||||
, "9" = rgb(0.04,0.49,0.51)
|
, "9" = rgb(0.04,0.49,0.51)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
consurf_bp_colours = c(#"0" = rgb(1.00,1.00,0.59)
|
||||||
|
"0" = rgb(1.00,1.00,0.59)
|
||||||
|
, "1" = rgb(0.63,0.16,0.37)
|
||||||
|
, "2" = rgb(0.94,0.49,0.67)
|
||||||
|
, "3" = rgb(0.98,0.78,0.86)
|
||||||
|
, "4" = rgb(0.98,0.92,0.96)
|
||||||
|
, "5" = rgb(1.00,1.00,1.00)
|
||||||
|
, "6" = rgb(0.84,0.94,0.94)
|
||||||
|
, "7" = rgb(0.65,0.86,0.90)
|
||||||
|
, "8" = rgb(0.29,0.69,0.75)
|
||||||
|
, "9" = rgb(0.04,0.49,0.51)
|
||||||
|
)
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
|
|
||||||
# Function name clashes with plyr and dplyr
|
# Function name clashes with plyr and dplyr
|
||||||
|
|
|
@ -28,7 +28,8 @@ lf_bp <- function(lf_df = lf_duet
|
||||||
, stat_grp_comp = c("R", "S")
|
, stat_grp_comp = c("R", "S")
|
||||||
, stat_method = "wilcox.test"
|
, stat_method = "wilcox.test"
|
||||||
, my_paired = FALSE
|
, my_paired = FALSE
|
||||||
, stat_label = c("p.format", "p.signif") ){
|
, stat_label = c("p.format", "p.signif")
|
||||||
|
) {
|
||||||
|
|
||||||
fwv = as.formula(paste0("~", facet_var))
|
fwv = as.formula(paste0("~", facet_var))
|
||||||
#fwv = reformulate(facet_var)
|
#fwv = reformulate(facet_var)
|
||||||
|
@ -57,13 +58,22 @@ lf_bp <- function(lf_df = lf_duet
|
||||||
, outlier.colour = NA
|
, outlier.colour = NA
|
||||||
#, position = position_dodge(width = 0.9)
|
#, position = position_dodge(width = 0.9)
|
||||||
, width = bp_width) +
|
, width = bp_width) +
|
||||||
geom_quasirandom(priority = "density"
|
geom_quasirandom(#priority = "density"
|
||||||
#, shape = 21
|
#, shape = 21
|
||||||
, size = dot_size
|
size = dot_size
|
||||||
, alpha = dot_transparency
|
, alpha = dot_transparency
|
||||||
, show.legend = FALSE
|
, show.legend = FALSE
|
||||||
, cex = 0.8
|
, cex = 0.8
|
||||||
, aes(colour = factor(eval(parse(text = colour_categ))) ))
|
, aes(
|
||||||
|
colour = factor(
|
||||||
|
eval(
|
||||||
|
parse(
|
||||||
|
text = colour_categ
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) + ggplot2::scale_color_manual(values = consurf_bp_colours)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
#Legend=factor(eval(parse(text = colour_categ)))
|
#Legend=factor(eval(parse(text = colour_categ)))
|
||||||
|
@ -71,16 +81,26 @@ lf_bp <- function(lf_df = lf_duet
|
||||||
p2 = p1 +
|
p2 = p1 +
|
||||||
#theme(legend.title=element_text('XXX')) + # Legend doesn't need a title)
|
#theme(legend.title=element_text('XXX')) + # Legend doesn't need a title)
|
||||||
|
|
||||||
geom_quasirandom(priority = "density"
|
geom_quasirandom(#priority = "density"
|
||||||
#, shape = 21
|
#, shape = 21
|
||||||
, size = dot_size
|
size = dot_size
|
||||||
, alpha = dot_transparency
|
, alpha = dot_transparency
|
||||||
, show.legend = FALSE
|
, show.legend = FALSE
|
||||||
# , fast = FALSE
|
# , fast = FALSE
|
||||||
, cex = 0.8
|
, cex = 0.8
|
||||||
, aes(colour = factor(eval(parse(text = colour_categ))) )
|
, aes(
|
||||||
|
colour = factor(
|
||||||
|
eval(
|
||||||
|
parse(
|
||||||
|
text = colour_categ
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
#, aes(colour = Legend)
|
#, aes(colour = Legend)
|
||||||
)
|
) +
|
||||||
|
ggplot2::scale_color_manual(values = consurf_bp_colours)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +135,7 @@ lf_bp <- function(lf_df = lf_duet
|
||||||
, method = stat_method
|
, method = stat_method
|
||||||
, paired = my_paired
|
, paired = my_paired
|
||||||
, label = stat_label[2])
|
, label = stat_label[2])
|
||||||
|
|
||||||
return(OutPlot)
|
return(OutPlot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
147
scripts/functions/lf_bp2.R
Normal file
147
scripts/functions/lf_bp2.R
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
#############################
|
||||||
|
# Barplots: ggplot
|
||||||
|
# stats +/-
|
||||||
|
# violin +/-
|
||||||
|
# barplot +/
|
||||||
|
# beeswarm
|
||||||
|
#############################
|
||||||
|
|
||||||
|
lf_bp2 <- function(lf_df = lf_duet
|
||||||
|
, p_title = "DUET-DDG"
|
||||||
|
, colour_categ = "outcome"
|
||||||
|
, x_grp = "mutation_info_labels"
|
||||||
|
, y_var = "param_value"
|
||||||
|
, facet_var = "param_type"
|
||||||
|
, n_facet_row = 1
|
||||||
|
, y_scales = "free_y"
|
||||||
|
, colour_bp_strip = "khaki2"
|
||||||
|
, dot_size = 3
|
||||||
|
, dot_transparency = 0.5
|
||||||
|
, violin_quantiles = c(0.25, 0.5, 0.75) # can be NULL
|
||||||
|
, my_ats = 22 # axis text size
|
||||||
|
, my_als = 20 # axis label size
|
||||||
|
, my_fls = 20 # facet label size
|
||||||
|
, my_pts = 22 # plot title size)
|
||||||
|
, make_boxplot = FALSE
|
||||||
|
#, bp_width = c("auto", 0.5)
|
||||||
|
, bp_width = "auto"
|
||||||
|
, add_stats = TRUE
|
||||||
|
, stat_grp_comp = c("R", "S")
|
||||||
|
, stat_method = "wilcox.test"
|
||||||
|
, my_paired = FALSE
|
||||||
|
, stat_label = c("p.format", "p.signif")
|
||||||
|
, monochrome = FALSE
|
||||||
|
) {
|
||||||
|
|
||||||
|
fwv = as.formula(paste0("~", facet_var))
|
||||||
|
#fwv = reformulate(facet_var)
|
||||||
|
|
||||||
|
# Only use the longer colour palette if there are many outcomes
|
||||||
|
if (length(levels(lf_df$outcome)) > 2) {
|
||||||
|
lf_bp_colours = consurf_bp_colours
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lf_bp_colours =NULL
|
||||||
|
#lf_bp_colours = hue_pal()(2)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (bp_width == "auto"){
|
||||||
|
bp_width = 0.5/length(unique(lf_df[[x_grp]]))
|
||||||
|
}else{
|
||||||
|
bp_width = bp_width
|
||||||
|
}
|
||||||
|
|
||||||
|
ggplot(lf_df, aes_string(x = x_grp, y = y_var)) +
|
||||||
|
|
||||||
|
|
||||||
|
facet_wrap(fwv
|
||||||
|
, nrow = n_facet_row
|
||||||
|
, scales = y_scales) +
|
||||||
|
|
||||||
|
ggplot2::scale_color_manual(values = lf_bp_colours) +
|
||||||
|
|
||||||
|
geom_violin(trim = T
|
||||||
|
, scale = "width"
|
||||||
|
#, position = position_dodge(width = 0.9)
|
||||||
|
, draw_quantiles = violin_quantiles) +
|
||||||
|
|
||||||
|
# Add formatting to graph
|
||||||
|
theme(axis.text.x = element_text(size = my_ats)
|
||||||
|
, axis.text.y = element_text(size = my_ats
|
||||||
|
, angle = 0
|
||||||
|
, hjust = 1
|
||||||
|
, vjust = 0)
|
||||||
|
, axis.title.x = element_text(size = my_ats)
|
||||||
|
, axis.title.y = element_text(size = my_ats)
|
||||||
|
, plot.title = element_text(size = my_pts
|
||||||
|
, hjust = 0.5
|
||||||
|
, colour = "black"
|
||||||
|
, face = "bold")
|
||||||
|
, strip.background = element_rect(fill = colour_bp_strip)
|
||||||
|
, strip.text.x = element_text(size = my_fls
|
||||||
|
, colour = "black")
|
||||||
|
, legend.title = element_text(color = "black"
|
||||||
|
, size = my_als)
|
||||||
|
, legend.text = element_text(size = my_ats)
|
||||||
|
, legend.direction = "vertical") +
|
||||||
|
|
||||||
|
labs(title = p_title
|
||||||
|
, x = ""
|
||||||
|
, y = "") +
|
||||||
|
|
||||||
|
if (add_stats){
|
||||||
|
my_comparisonsL <- list( stat_grp_comp )
|
||||||
|
|
||||||
|
stat_compare_means(comparisons = my_comparisonsL
|
||||||
|
, method = stat_method
|
||||||
|
, paired = my_paired
|
||||||
|
, label = stat_label[2])
|
||||||
|
|
||||||
|
|
||||||
|
if (make_boxplot){
|
||||||
|
geom_boxplot(fill = "white"
|
||||||
|
, outlier.colour = NA
|
||||||
|
#, position = position_dodge(width = 0.9)
|
||||||
|
, width = bp_width) +
|
||||||
|
|
||||||
|
geom_quasirandom(#priority = "density"
|
||||||
|
#, shape = 21
|
||||||
|
size = dot_size
|
||||||
|
, alpha = dot_transparency
|
||||||
|
, show.legend = FALSE
|
||||||
|
, cex = 0.8
|
||||||
|
, aes(
|
||||||
|
colour = factor(
|
||||||
|
eval(
|
||||||
|
parse(
|
||||||
|
text = colour_categ
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
geom_quasirandom(
|
||||||
|
size = dot_size
|
||||||
|
, alpha = dot_transparency
|
||||||
|
, show.legend = FALSE
|
||||||
|
# , fast = FALSE
|
||||||
|
, cex = 0.8
|
||||||
|
, aes(
|
||||||
|
colour = factor(
|
||||||
|
eval(
|
||||||
|
parse(
|
||||||
|
text = colour_categ
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#lf_bp2(lf_consurf)
|
|
@ -110,15 +110,15 @@ LogoPlotCustomH <- function(plot_df
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class(logo_dfP_wf)
|
#class(logo_dfP_wf)
|
||||||
|
|
||||||
rownames(logo_dfP_wf) = logo_dfP_wf[,1]
|
rownames(logo_dfP_wf) = logo_dfP_wf[,1]
|
||||||
dim(logo_dfP_wf)
|
#dim(logo_dfP_wf)
|
||||||
|
|
||||||
logo_dfP_wf = logo_dfP_wf[,-1]
|
logo_dfP_wf = logo_dfP_wf[,-1]
|
||||||
str(logo_dfP_wf)
|
#str(logo_dfP_wf)
|
||||||
|
|
||||||
colnames(logo_dfP_wf)
|
#colnames(logo_dfP_wf)
|
||||||
position_or = as.numeric(colnames(logo_dfP_wf))
|
position_or = as.numeric(colnames(logo_dfP_wf))
|
||||||
|
|
||||||
######################################
|
######################################
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue