Change log2FoldChange range – plotMA

You can use base R graphics to make these plots. The data is sitting there in columns of the res object, so you can filter it directly, and use boolean vectors to pick out the things you need:

# make sure there are no NA values
sum(is.na(res$log2FoldChange))

# choose some significance threshold
# (i use the name iv to remind myself it's an index vector)
iv.sig <- res$padj < 0.001 

# genes up > 1
iv.up <- res$log2FoldChange > 1 & iv.sig

# genes down  < -1
iv.dn <- res$log2FoldChange < -1 & iv.sig

# make an MA plot
plot(log2(res$baseMean + 1), res$log2FoldChange, pch=".", col="grey",
     main="MA plot", xlab="log2(baseMean)", ylab="Log2FC")
points(log2(res$baseMean + 1)[iv.up], res$log2FoldChange[iv.up], col="red", pch=20)
points(log2(res$baseMean + 1)[iv.dn], res$log2FoldChange[iv.dn], col="green", pch=20)

enter image description here

# or make a Volcano plot
plot(res$log2FoldChange, abs(res$stat), pch=".", col="grey",
     main="Volcano Plot", xlab="Log2FC", ylab="Sig Stat")
points(res$log2FoldChange[iv.up], abs(res$stat)[iv.up], col="red", pch=20)
points(res$log2FoldChange[iv.dn], abs(res$stat)[iv.dn], col="green", pch=20)

enter image description here

# get the genes of interest, up or down
goi <- rownames(res)[iv.up | iv.dn]

Read more here: Source link