How to colour all points that agree with multiple conditions
1
0
Entering edit mode
3.9 years ago
n.tear ▴ 80

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 • 636 views
ADD COMMENT
1
Entering edit mode
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?

ADD REPLY
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode
3.9 years ago
caggtaagtat ★ 1.9k

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()
ADD COMMENT

Login before adding your answer.

Traffic: 1772 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