Skip to contents

Makes barplots from Enrichr data

Usage

EnrichrDotPlot(
  seurat_obj,
  database,
  mods = "all",
  n_terms = 3,
  break_ties = TRUE,
  logscale = TRUE,
  wgcna_name = NULL,
  ...
)

Arguments

seurat_obj

A Seurat object

database

name of the enrichr database to plot.

mods

names of modules to plot. All modules are plotted if mods='all' (default)

n_terms

number of enriched terms to plot for each module

break_ties

logical controlling whether or not to randomly select terms with equal enrichments to precisely enforce n_terms.

logscale

logical controlling whether to plot the enrichment on a log scale.

wgcna_name

The name of the hdWGCNA experiment in the seurat_obj@misc slot

Examples

EnrichrDotPlot
#> function (seurat_obj, database, mods = "all", n_terms = 3, break_ties = TRUE, 
#>     logscale = TRUE, wgcna_name = NULL, ...) 
#> {
#>     if (is.null(wgcna_name)) {
#>         wgcna_name <- seurat_obj@misc$active_wgcna
#>     }
#>     modules <- GetModules(seurat_obj, wgcna_name)
#>     if (mods == "all") {
#>         mods <- levels(modules$module)
#>         mods <- mods[mods != "grey"]
#>     }
#>     enrichr_df <- GetEnrichrTable(seurat_obj, wgcna_name)
#>     mod_colors <- dplyr::select(modules, c(module, color)) %>% 
#>         dplyr::distinct()
#>     enrichr_df$color <- mod_colors[match(enrichr_df$module, mod_colors$module), 
#>         "color"]
#>     wrapText <- function(x, len) {
#>         sapply(x, function(y) paste(strwrap(y, len), collapse = "\n"), 
#>             USE.NAMES = FALSE)
#>     }
#>     plot_df <- enrichr_df %>% subset(db == database & module %in% 
#>         mods) %>% group_by(module) %>% top_n(n_terms, wt = Combined.Score)
#>     if (break_ties) {
#>         plot_df <- do.call(rbind, lapply(plot_df %>% group_by(module) %>% 
#>             group_split, function(x) {
#>             x[sample(n_terms), ]
#>         }))
#>     }
#>     plot_df$Term <- wrapText(plot_df$Term, 45)
#>     plot_df$module <- factor(as.character(plot_df$module), levels = levels(modules$module))
#>     plot_df <- arrange(plot_df, module)
#>     plot_df$Term <- factor(as.character(plot_df$Term), levels = unique(as.character(plot_df$Term)))
#>     if (logscale) {
#>         plot_df$Combined.Score <- log(plot_df$Combined.Score)
#>         lab <- "Enrichment\nlog(combined score)"
#>         x <- 0.2
#>     }
#>     else {
#>         lab <- "Enrichment\n(combined score)"
#>         x <- 5
#>     }
#>     p <- plot_df %>% ggplot(aes(x = module, y = Term)) + geom_point(aes(size = Combined.Score), 
#>         color = plot_df$color) + RotatedAxis() + ylab("") + xlab("") + 
#>         labs(size = lab) + scale_y_discrete(limits = rev) + ggtitle(database) + 
#>         theme(plot.title = element_text(hjust = 0.5), axis.line.x = element_blank(), 
#>             axis.line.y = element_blank(), panel.border = element_rect(colour = "black", 
#>                 fill = NA, size = 1))
#>     p
#> }
#> <bytecode: 0x7f96312257b8>
#> <environment: namespace:hdWGCNA>