PlotModuleTraitCorrelation.Rd
Plotting function for Module Preservation statistics
PlotModuleTraitCorrelation(
seurat_obj,
high_color = "red",
mid_color = "grey90",
low_color = "blue",
label = NULL,
label_symbol = "stars",
plot_max = NULL,
text_size = 2,
text_color = "black",
text_digits = 3,
combine = TRUE,
wgcna_name = NULL
)
A Seurat object
color for positive correlation
color for zero correlation
color for negative correlation
logical determining whether to add p-val label in each cell of the heatmap
show the labels as 'stars' or as 'numeric'
maximum value of correlation to show on the colorbar
size of the labels
color of the text labels
how many digits to show in the text labels
logical determining whether to plot as one combined plot (TRUE) or to return individual plots as a list (FALSE)
PlotModulePreservation
#> function (seurat_obj, name, statistics = "summary", plot_labels = TRUE,
#> label_size = 4, mod_point_size = 4, wgcna_name = NULL)
#> {
#> if (is.null(wgcna_name)) {
#> wgcna_name <- seurat_obj@misc$active_wgcna
#> }
#> mod_pres <- GetModulePreservation(seurat_obj, name, wgcna_name)
#> obs_df <- mod_pres$obs
#> Z_df <- mod_pres$Z
#> modules <- GetModules(seurat_obj, wgcna_name)
#> module_colors <- modules %>% dplyr::select(c(module, color)) %>%
#> distinct
#> mods <- rownames(Z_df)
#> mod_colors <- module_colors$color[match(mods, module_colors$module)]
#> mod_colors = ifelse(is.na(mod_colors), "gold", mod_colors)
#> if (statistics == "summary") {
#> stat_list <- c("Zsummary.qual", "Zsummary.pres")
#> }
#> else if (statistics == "rank") {
#> stat_list <- colnames(obs_df[, -1])[grepl("Rank", colnames(obs_df[,
#> -1]))]
#> }
#> else if (statistics == "all") {
#> stat_list <- c(colnames(obs_df[, -1])[grepl("Rank", colnames(obs_df[,
#> -1]))], colnames(Z_df[, -1]))
#> }
#> else {
#> stat_list <- statistics
#> }
#> stat_list <- stat_list[stat_list != "moduleSize"]
#> plot_list <- list()
#> for (statistic in stat_list) {
#> print(statistic)
#> if (statistic %in% colnames(obs_df)) {
#> values <- obs_df[, statistic]
#> }
#> else if (statistic %in% colnames(Z_df)) {
#> values <- Z_df[, statistic]
#> }
#> else {
#> stop("Invalid name for statistic.")
#> }
#> plot_df <- data.frame(module = mods, color = mod_colors,
#> value = values, size = Z_df$moduleSize)
#> plot_df <- plot_df %>% subset(!(module %in% c("grey",
#> "gold")))
#> if (grepl("Rank", statistic)) {
#> cur_p <- plot_df %>% ggplot(aes(x = size, y = value,
#> fill = module, color = module)) + geom_point(size = mod_point_size,
#> pch = 21, color = "black") + scale_y_reverse()
#> }
#> else {
#> cur_p <- plot_df %>% ggplot(aes(x = size, y = value,
#> fill = module, color = module)) + geom_rect(data = plot_df[1,
#> ], aes(xmin = 0, xmax = Inf, ymin = -Inf, ymax = 2),
#> fill = "grey75", alpha = 0.8, color = NA) + geom_rect(data = plot_df[1,
#> ], aes(xmin = 0, xmax = Inf, ymin = 2, ymax = 10),
#> fill = "grey92", alpha = 0.8, color = NA) + geom_point(size = mod_point_size,
#> pch = 21, color = "black")
#> }
#> cur_p <- cur_p + scale_fill_manual(values = plot_df$color) +
#> scale_color_manual(values = plot_df$color) + scale_x_continuous(trans = "log10") +
#> ylab(statistic) + xlab("Module Size") + ggtitle(statistic) +
#> NoLegend() + theme(plot.title = element_text(hjust = 0.5))
#> if (plot_labels) {
#> cur_p <- cur_p + ggrepel::geom_text_repel(label = plot_df$module,
#> size = label_size, max.overlaps = Inf, color = "black")
#> }
#> plot_list[[statistic]] <- cur_p
#> }
#> if (length(plot_list) == 1) {
#> return(plot_list[[1]])
#> }
#> plot_list
#> }
#> <bytecode: 0x7f77f0389fe8>
#> <environment: namespace:hdWGCNA>