【发布时间】:2015-11-12 01:07:37
【问题描述】:
我是 ggplot2 的新手,我很难通过 2 个因素为每个基因制作条形图。
我想通过 2 个因素分别绘制每个基因:“cell_type”和“age”。
x 轴代表“细胞类型”(6) 类别,每个“细胞类型”类别内应有 5 个代表“年龄”类别的条形图。 y 轴代表基因表达值(平均值 + 误差线)。
我的代码:
mat= t(exprs(eSet))
colnames(mat) = fData(eSet)$Symbol
rownames(mat = pData(eSet)$genotype
GENOTYPE <- rownames(mat)
AGE <- pData(eSet)$age
d.f_all_genes2 <- data.frame(GENOTYPE, AGE, mat)
d.f_all_genes2[1:3,1:10]
GENOTYPE AGE X1.2.SBSRNA4 A1BG A1BG.AS1 A1CF A2LD1 A2M A2ML1 A2MP1
1 rag_a 54 0 0 0 0 0 0 0 0
2 rag_wt 54 0 0 0 0 0 18 0 0
3 wt_wt 54 0 0 0 0 0 1 0 0
melted <- melt(d.f_all_genes2, id.vars="GENOTYPE")
head(melted)
GENOTYPE variable value
1 rag_a AGE 54
2 rag_wt AGE 54
3 wt_wt AGE 54
不幸的是,我失去了所有的基因。
我还打算做以下事情:
means <- ddply(melted, c("AGE", "variable"), summarise, mean=mean(value))
means.sem <- ddply(melted, c("AGE", "variable"), summarise, mean=mean (value),sem=sd(value)/sqrt(length(value)))
means.sem <- transform(means.sem, lower=mean-sem, upper=mean+sem)
ggplot(means[means$variable == "GENE of Interest=Symbol",], aes(x = factor(AGE), y = mean)) + geom_bar(stat= "identity", colour = "blue", outlier.shape = NA)+ facet_grid(~GENOTYPE) + facet_wrap(~variable) + ylab(expression(paste(Log[2], " Expression Values"))) + theme(axis.text=element_text(size=13, color="black"),axis.title=element_text(size=12, face="bold",color="black"), plot.title=element_text(size=14,face="bold", color="black"), strip.text.x = element_text(colour = "black", face= "bold",angle = 0, size = 20))
非常感谢任何关于如何使其发挥作用的建议和帮助。
非常感谢。
【问题讨论】:
-
根据描述,您的
id.vars似乎应该包括AGE和GENOTYPE。 -
欢迎来到 SO!请填写完整的reproducible example,这将增加您获得完整答案的几率。