fgsea gene names
1
0
Entering edit mode
2.8 years ago
barix ▴ 20

Hi all!

Is it possible to plot gene names below the bar plot? I'm attaching pic of what I mean.

Thank you!

fig

fgsea • 1.4k views
ADD COMMENT
0
Entering edit mode
2.8 years ago

The code for the function is quite simple:

fgsea::plotEnrichment
function (pathway, stats, gseaParam = 1, ticksSize = 0.2) 
{
    rnk <- rank(-stats)
    ord <- order(rnk)
    statsAdj <- stats[ord]
    statsAdj <- sign(statsAdj) * (abs(statsAdj)^gseaParam)
    statsAdj <- statsAdj/max(abs(statsAdj))
    pathway <- unname(as.vector(na.omit(match(pathway, names(statsAdj)))))
    pathway <- sort(pathway)
    gseaRes <- calcGseaStat(statsAdj, selectedStats = pathway, 
        returnAllExtremes = TRUE)
    bottoms <- gseaRes$bottoms
    tops <- gseaRes$tops
    n <- length(statsAdj)
    xs <- as.vector(rbind(pathway - 1, pathway))
    ys <- as.vector(rbind(bottoms, tops))
    toPlot <- data.frame(x = c(0, xs, n + 1), y = c(0, ys, 0))
    diff <- (max(tops) - min(bottoms))/8
    x = y = NULL
    g <- ggplot(toPlot, aes(x = x, y = y)) + geom_point(color = "green", 
        size = 0.1) + geom_hline(yintercept = max(tops), colour = "red", 
        linetype = "dashed") + geom_hline(yintercept = min(bottoms), 
        colour = "red", linetype = "dashed") + geom_hline(yintercept = 0, 
        colour = "black") + geom_line(color = "green") + theme_bw() + 
        geom_segment(data = data.frame(x = pathway), mapping = aes(x = x, 
            y = -diff/2, xend = x, yend = diff/2), size = ticksSize) + 
        theme(panel.border = element_blank(), panel.grid.minor = element_blank()) + 
        labs(x = "rank", y = "enrichment score")
    g
}

So, I would just modify this to retain gene name in the object toPlot, and then use ggrepel::geom_text_repel() to add these genes to the plot. ggrepel is necessary because there is no way that you will be able to fit all labels on that plot.

Kevin

ADD COMMENT
0
Entering edit mode

Thank you for the help! Since I've just started bioinformatics (and working in R), could you please explain/help how to modify code to retain gene name in the object toPlot?

ADD REPLY
0
Entering edit mode

Hi, I do not have time to write this code for you - sorry (somebody else may [have time]).

ADD REPLY

Login before adding your answer.

Traffic: 2957 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6