I need to attribute color in a scatterplot where I have multiple conditions. The file is df below. I am plotting Tissue1 vs Tissue2 values. I would like to colour as follows:
pvalue1 AND pvalue2 < 0.1 = "yellow"
pvalue1 ≤ 0.1 = "green" (if pvalue2 >0.1 or NA)
pvalue2 ≤ 0.1 = "red" (if pvalue1 >0.1 or NA)
(all other = "grey")
df:
rowname Tissue1 pvalue1 Tissue2 pvalue2
gene1 1.3 0.7 1.6 0.09
gene2 -0.9 0.07 -0.7 0.065
gene3 2 0.9 1.65 0.9
gene4 1.7 0.07 1.6 0.09
I am plotting Tissue1 vs Tissue2 using ggplot:
ggplot(data=data.frame(x=df$Tissue1,y=df$Tissue2),
aes(x,y)
)+ geom_point(col="grey30") +
geom_abline(stat = "abline", colour = "red", size = 1) +
xlab("foldchange Tissue1") + ylab("foldchange Tissue2")
I have tried creating factors, but haven't been able to add them with the ifelse function.
Sig1 <- subset(df, df$pvalue1< 0.1)
Sig2 <- subset(df, df$pvalue2 < 0.1)
I'd appreciate some help with this. Thanks!
Aucun commentaire:
Enregistrer un commentaire