This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Is there a way to mark up specific genes in MA-plot?

Dear, everyone,

I have this table, and created MAplot using the following steps. In this plot, I would like to mark up only the genes that I specify:for example, I would like to display the gene name in a different color.

What is the best way to do this? Thank you for reading.

                gene      logFC    logCPM       PValue          FDR
1    Ab_DN4787_c0_g1   8.701543  6.481583 8.718089e-95 1.898277e-90
2    Ab_DN9125_c0_g3  -8.575896  6.311612 5.984297e-77 6.515104e-73
3    Ab_DN4518_c0_g2  -3.880269  8.601647 1.125398e-68 8.168139e-65
4   Ab_DN11435_c0_g1  13.802492  6.566147 2.599560e-64 1.415071e-60
5   Ab_DN18643_c0_g1  13.949692  6.713022 1.070026e-62 4.659751e-59

enter image description here

> res <- read.table("input", sep="\t", header=T, quote = "\"", fill = T)
> A <- res$logCPM
> M <- res$logFC
> plot(A, M, xlab="Average log CPM", ylab="log-fold-change", pch=16, cex=0.4)
edger ggplot plot ma r

For OP issue, I would suggest you to use "enhancedvolcano" library from Bioconductor or use of ggplot (for plotting) and ggrepel (for labeling genes of interest)

with basic plotting and example data:

genes=c("Ab_DN4787_c0_g1","Ab_DN9125_c0_g3") # genes of interest
subres = subset(res, gene %in% genes)
a = subres$logCPM
m = subres$logFC
A <- res$logCPM
M <- res$logFC
plot(A, M, xlab="Average log CPM", ylab="log-fold-change", pch=16, cex=0.4)
text(a,m,col="steelblue",subres$gene, pos = 4,pch=16) # For labeling of genes of interest
points(a,m,col="steelblue", pch=16) # For highlighting genes of interest

highlight_genes

Thank you very much for your advice. I can make the same figure in ggplot2 with the following command, what options do I need in this case?

g <- ggplot(res, aes(x=logCPM, y=logFC)) +
geom_point(size=1) +
scale_colour_manual(values = c("black", "red")) +
scale_fill_manual(values = c("black", "red"), breaks=c("0", "1"), labels=c("non DEG", "DEG")) +
theme(legend.title=element_blank()) +
ggtitle("title")
print(g)
library(ggplot2)
library(ggrepel)

genes=c("Ab_DN4787_c0_g1","Ab_DN9125_c0_g3")

ggplot(res, aes(logCPM, logFC)) +
    geom_point() +
    theme_bw() +
    theme(legend.position = "none") +
    geom_point(
        data = subset(res, gene %in% genes),
        aes(logCPM, logFC),
        size = 2,
        color = 'red'
    ) +
    geom_text_repel(
        data = subset(res, gene %in% genes),
        aes(logCPM, logFC, label = gene),
        size = 4,
        color = "steelblue"
    )

highlight_genes

Thank you very much! I have been able to create beautiful graph thanks to you.

1 answer

Add text from plot

> plot(A, M, xlab="Average log CPM", ylab="log-fold-change", pch=16, cex=0.4) 
> text(labels= c("gene A", "gene B"), pos=2)

I prefer using ggplot.

> text(labels= c("gene A", "gene B"), pos=2)

One needs to supply x and y coordinates of genes of interest for correct highlighting/labeling.

Thank you very much for your advice. I can make the same figure in ggplot2 with the following command, what options do I need in this case?

g <- ggplot(res, aes(x=logCPM, y=logFC)) +
geom_point(size=1) +
scale_colour_manual(values = c("black", "red")) +
scale_fill_manual(values = c("black", "red"), breaks=c("0", "1"), labels=c("non DEG", "DEG")) +
theme(legend.title=element_blank()) +
ggtitle("title")
print(g)

Log in to answer this question.