This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to colour all points that agree with multiple conditions

Hello,

I am trying to make an MA plot of all the genes and colour in red all those that have a padj value of <0.05 AND have a >1 OR <-1 LFC

I cant find what syntax to use

res.sLFCdf

ggplot(res.sLFCdf, 
aes(x = log2(baseMean), y=log2FoldChange, col= res.sIHW$padj<0.05 & res.sIHW$shrunkLFC > 1 or res.sIHW$shrunkLFC < -1 ))
+ geom_point(alpha=0.4) 
+ scale_colour_manual(values=c("grey","red")) 
+ xlab("Log2 mean of normalized counts") 
+   ylab("Log2 fold change") + geom_hline(yintercept=c(-1,1), linetype="dashed", color = "black") 
+ theme_minimal()

Many thanks for any help

Nathan

r rna-seq

Add another field that reflects if the conditions are satisfied and color based on that field?

ggplot(df,
       aes(
           x = res.sLFCdf,
           y = log2(baseMean),
           col = res.sIHW$padj<0.05 & abs(res.sIHW$shrunkLFC) > 1 )
       )+ 
    geom_point(alpha = 0.4)+ 
    scale_colour_manual(values = c("grey", "red"))+ 
    xlab("Log2 mean of normalized counts")+   
    ylab("Log2 fold change") + 
    geom_hline(yintercept = c(-1, 1),linetype = "dashed",color = "black")+ 
    theme_minimal()+
    theme(legend.position = "none")

Btw, is there any reason for taking color values from a different frame /data?

1 answer

If res.sLFCdf is da data frame, you could do something like

res.sLFCdf$coloring <- "not"
res.sLFCdf$coloring[res.sLFCdf$coloring$padj< 0.05 & (res.sLFCdf$log2FoldChange> 1 | res.sLFCdf$log2FoldChange< -1)] <- "colored"

And then:

ggplot(res.sLFCdf, 
aes(x = log2(baseMean), y=log2FoldChange, col= coloring  ))
+ geom_point(alpha=0.4) 
+ scale_colour_manual(values=c("grey","red")) 
+ xlab("Log2 mean of normalized counts") 
+   ylab("Log2 fold change") + geom_hline(yintercept=c(-1,1), linetype="dashed", color = "black") 
+ theme_minimal()

Log in to answer this question.