Hello everyone!
I tried to make a basic scatter plot with R using gene expression data.
#import data:
oldmice <- read.table("oldmice.txt", header = TRUE)
youngmice <- read.table("youngmice.txt", header = TRUE)
Imported data contains: format is the same for both imported data but MGE has different values.
gene MGE
Sox17 -6.74193774617653
Mrpl15 -0.212567471203473
Lypla1 -0.711251006455475
and so on..
Made basic volcano plot using: youngmice$MGE vs oldmice$MGE
plot(oldmice$MGE, youngmice$MGE, main="old vs young mice!!",
xlab="oldmice$MGE ", ylab="youngmice$MGE ", pch=19)
My question is how to color "genes" which is in multiple_gene_lists into oldmice$MGE, youngmice$MGE? (which should label the only multiple_gene_list which are in multiple_gene_lists into oldmice$MGE, youngmice$MGE)
Here is my multiple_gene_list
multiple_gene_list <- read.table("multiple_gene_list.txt", header = TRUE)
multiple_gene_list <- as.vector(multiple_gene_list )
multiple_gene_list contains:
gene
Six6
Arl2
Tmem74B
Rab9B
Rasgef1B
Ccne1
Apln
Spag7
C17Orf59
Krtap4-4
And my goal is to only label multiple_gene_list in oldmice$MGE, youngmice$MGE. I also tried the following code but failed!
with(subset(ASC_oldmice_exprs, ASC_oldmice_exprs$gene %in% multiple_gene_list$gene), points(ASC_youngmice_exprs$MGE, pch=20, col="red"))
Thank you!
1 answer
Hey, here is a simple way to do it, and to also have a different shape for the genes of interest:
oldmice <- data.frame(gene = c("BRCA1","BRCA2","BRCC3","TP53","ATM"),
MGE = c(-6,-5,-8,-7,-6))
youngmice <- data.frame(gene = c("BRCA1","BRCA2","BRCC3","TP53","ATM"),
MGE = c(-6.5,-7,-4,-7,-8))
multiple_gene_list <- c("TP53","ATM")
1, Create a default colour vector:
mycol <- rep("grey50", length(youngmice$gene))
mycol
[1] "grey50" "grey50" "grey50" "grey50" "grey50"
2, Set a colour for the genes of interest:
mycol[which(youngmice$gene %in% multiple_gene_list)] <- "firebrick1"
mycol
[1] "grey50" "grey50" "grey50" "firebrick1" "firebrick1"
3, Same as 1 & 2 but for shape (pch):
mypch <- rep(19, length(youngmice$gene))
mypch[which(youngmice$gene %in% multiple_gene_list)] <- 18
mypch
[1] 19 19 19 18 18
4, Plot data:
plot(oldmice$MGE, youngmice$MGE, main = "old vs young mice!!",
xlab = "oldmice$MGE ", ylab = "youngmice$MGE ", pch = mypch, col = mycol, cex = 5.0,
xlim = c(-10, -2), ylim = c(-10, -2))
text(
subset(oldmice, gene %in% multiple_gene_list)$MGE,
subset(youngmice, gene %in% multiple_gene_list)$MGE - 0.45,
lab = subset(youngmice, gene %in% multiple_gene_list)$gene,
cex = 1.0)
You can also set the labels this way:
mylab <- as.character(youngmice$gene)
mylab[-which(youngmice$gene %in% multiple_gene_list)] <- ""
mylab
[1] "" "" "" "TP53" "ATM"
plot(oldmice$MGE, youngmice$MGE, main = "old vs young mice!!",
xlab = "oldmice$MGE ", ylab = "youngmice$MGE ", pch = mypch, col = mycol, cex = 5.0,
xlim = c(-10, -2), ylim = c(-10, -2))
text(oldmice$MGE, youngmice$MGE - 0.45,
lab = mylab,
cex = 1.0)
Log in to answer this question.

