Hi all,
I have expression measure of genes (two sets: target and contro genes) as measured by RNAseq, which is computed in tabular matrix.
head(A)
V1 V2 V3 V4 V5 V6
1 chr20:38788661-38812050_ENSDART00000136771 1.912 1.912 1.912 4.770 0.703
2 chr4:13971999-13980660_ENSDART00000067040 0.502 0.502 0.502 1.242 0.011
V7 V8 V9 V10 V11 V12 V13
1 0.137 6.534 4.689 7.086 2.646 4.376 0.684
2 0.007 0.684 1.125 2.819 2.392 1.406 0.364
head(B)
V1 V2 V3 V4 V5 V6
1 chr19:24974067-24977991_ENSDART00000052421 0.005 0.005 0.005 0.025 0.139
2 chr8:26148102-26150871_ENSDART00000049793 2.312 2.312 2.312 6.153 1.109
3 chr8:47908733-47913950_ENSDART00000025620 2.446 2.446 2.446 9.660 5.411
V7 V8 V9 V10 V11 V12 V13
1 0.807 0.010 0.232 5.963 0.022 0.149 3.162
2 0.291 4.556 3.214 16.486 2.158 5.599 0.939
3 7.745 11.614 13.150 51.680 8.557 18.356 36.378
PLOT:
par (mfrow=c(1,2))
plot (log2(A$V2/A$V5), log2(A$V8/A$V11), xlab="log2(FC)", ylab="log2(FC)", xlim=c(-5,5), ylim=c(-5,5), col="red")
abline(v=0, lty=2); abline (h=0, lty=2)
plot (log2(B$V2/B$V5), log2(B$V8/B$V11), xlab="log2(FC)", ylab="log2(FC)", col="blue", xlim=c(-5,5), ylim=c(-5,5))
abline(v=0, lty=2); abline (h=0, lty=2)
How could i plot both in the same plot?
cheers
Chirag
3 answers
If I were you I would try using your first plot as is, but for the second plot instead of using the plot function, use points e.g.
plot (log2(A$V2/A$V5), log2(A$V8/A$V11), xlab="log2(FC)", ylab="log2(FC)", xlim=c(-5,5), ylim=c(-5,5), col="red")
points(log2(B$V2/B$V5), log2(B$V8/B$V11), col="blue")
abline(v=0, lty=2); abline (h=0, lty=2)
You could also use par(new=TRUE) instead. i.e.
plot (log2(A$V2/A$V5), log2(A$V8/A$V11), xlab="log2(FC)", ylab="log2(FC)", xlim=c(-5,5), ylim=c(-5,5), col="red")
par(new =TRUE)
plot (log2(B$V2/B$V5), log2(B$V8/B$V11), xlab="", ylab="", col="blue", xlim=c(-5,5), ylim=c(-5,5))
abline(v=0, lty=2); abline (h=0, lty=2)
edit:
Also, if the A$V2 etc doesn't work you may want to use A[,2] instead.
cols=c(rep("red",2),rep("blue",3))
with(rbind(A,B), plot(log2(V2/V5), log2(V8/V11), xlab="log2(FC)", ylab="log2(FC)", xlim=c(-5,5), ylim=c(-5,5), col=cols))
abline(v=0, lty=2); abline (h=0, lty=2)
You could also just add the colors as a column, which would make life easier if using ggplot2.
a)
plot(c(log2(A$V2/A$V5),log2(B$V2/B$V5)), c(...), col=c(rep("red", nrow(A)),rep("blue", nrow(B)))
b)
with ggplot2 its much more elegant. You would have to create one data frame with a structure like:
gene name x y type
gene1 3.2 1.2 control
....
geneN 1.2 3.2 target
and then ggplot(df, aes(x=x,y=y, colour=type))+geom_point()
Log in to answer this question.
Thank you very much guys !!