PlotDMEsVolcano.Rd
Plotting function for the results of FindDMEs and FindAllDMEs
PlotDMEsVolcano(
seurat_obj,
DMEs,
plot_labels = TRUE,
mod_point_size = 4,
label_size = 4,
show_cutoff = TRUE,
wgcna_name = NULL
)
dataframe output from FindDMEs or FindAllDMEs
logical determining whether to plot the module labels
the size of the points in each plot
the size of the module labels
logical determining whether to plot the significance cutoff. Should set this to FALSE if using facet_wrap.
The name of the hdWGCNA experiment in the seurat_obj@misc slot
A ggplot object
PlotDMEsVolcano
#> function (seurat_obj, DMEs, plot_labels = TRUE, mod_point_size = 4,
#> label_size = 4, show_cutoff = TRUE, wgcna_name = NULL)
#> {
#> if (is.null(wgcna_name)) {
#> wgcna_name <- seurat_obj@misc$active_wgcna
#> }
#> DMEs <- na.omit(DMEs)
#> lowest <- DMEs %>% subset(p_val_adj != 0) %>% top_n(-1, wt = p_val_adj) %>%
#> .$p_val_adj
#> DMEs$p_val_adj <- ifelse(DMEs$p_val_adj == 0, lowest, DMEs$p_val_adj)
#> max_fc <- max(abs(DMEs$avg_log2FC))
#> max_fc <- DMEs %>% subset(abs(avg_log2FC) != Inf) %>% .$avg_log2FC %>%
#> max
#> DMEs$avg_log2FC <- ifelse(DMEs$avg_log2FC == -Inf, -1 * max_fc,
#> DMEs$avg_log2FC)
#> DMEs$avg_log2FC <- ifelse(DMEs$avg_log2FC == Inf, max_fc,
#> DMEs$avg_log2FC)
#> modules <- GetModules(seurat_obj, wgcna_name) %>% subset(module !=
#> "grey") %>% mutate(module = droplevels(module))
#> module_colors <- modules %>% dplyr::select(c(module, color)) %>%
#> distinct
#> mods <- levels(modules$module)
#> mods <- mods[mods %in% DMEs$module]
#> mod_colors <- module_colors$color
#> names(mod_colors) <- as.character(module_colors$module)
#> DMEs$anno <- ifelse(DMEs$p_val_adj < 0.05, DMEs$module, "")
#> xmax <- max_fc
#> p <- DMEs %>% ggplot(aes(x = avg_log2FC, y = -log10(p_val_adj),
#> fill = module, color = module))
#> if (show_cutoff) {
#> p <- p + geom_vline(xintercept = 0, linetype = "dashed",
#> color = "grey75", alpha = 0.8) + geom_rect(data = DMEs[1,
#> ], aes(xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = -log10(0.05)),
#> fill = "grey75", alpha = 0.8, color = NA)
#> }
#> p <- p + geom_point(size = mod_point_size, pch = 21, color = "black")
#> if (plot_labels) {
#> p <- p + ggrepel::geom_text_repel(aes(label = anno),
#> color = "black", min.segment.length = 0, max.overlaps = Inf,
#> size = label_size)
#> }
#> p <- p + scale_fill_manual(values = mod_colors) + scale_color_manual(values = mod_colors) +
#> xlim((-1 * xmax) - 0.1, xmax + 0.1) + xlab(bquote("Average log"[2] ~
#> "(Fold Change)")) + ylab(bquote("-log"[10] ~ "(Adj. P-value)")) +
#> theme(panel.border = element_rect(color = "black", fill = NA,
#> size = 1), panel.grid.major = element_blank(), axis.line = element_blank(),
#> plot.title = element_text(hjust = 0.5), legend.position = "bottom") +
#> NoLegend()
#> p + NoLegend()
#> }
#> <bytecode: 0x7f77d3d56268>
#> <environment: namespace:hdWGCNA>