Question: barplot with ggplot2 for gene expression
0
gravatar for alakatos
3.7 years ago by
alakatos90
United States
alakatos90 wrote:

Hi All,

I am having difficulties to make a barplot for  each gene by 2 factors with ggplot2.  I tried to modify my boxplot code but it does not work.

I would like to plot each gene by 2 factors: "cell_type" and "age". x-axis represents "cell type" categories  and inside each "cell type" category should be 5 bars representing the "age" categories. The y axis is the gene expression value  (mean + error bars). 

My code:

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")  
 
 

Unfortunately, the genes are missing.

> head(melted)
          GENOTYPE   variable value
1           rag_a       AGE     54
2           rag_wt      AGE     54
3            wt_wt      AGE     54
 
 

I have not tested this code  yet below:

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",], 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))

Any help is highly appreciated.

Thank you very much in advance.

Anita

My boxplot code that works

mat= t(exprs(eSet))
colnames(mat) = fData(eSet)$Symbol
rownames(mat = pData(eSet)$genotype
GENOTYPE <- rownames(mat)

d.f_all_genes <- data.frame(GENOTYPE, mat_all_genes)
d.f2_all_genes <- melt(d.f_all_genes, id.vars = "GENOTYPE")
colorsg = c("royalblue3","green1", "violetred1", "red1", "blue", "black", "red3","pink","orange")

plot <- ggplot(d.f2_all_genes[d.f2_all_genes$variable == "GENE of Interes",], aes(x = GENOTYPE, y = value))  + geom_boxplot(fill = colorsg, colour = "black", outlier.shape = NA) + geom_jitter(position = position_jitter(height = .5, width = .05), size=3, alpha=1) + 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)) + coord_flip()

 
 

 

ADD COMMENTlink modified 3.7 years ago by James W. MacDonald49k • written 3.7 years ago by alakatos90
Answer: barplot with ggplot2 for gene expression
0
gravatar for James W. MacDonald
3.7 years ago by
United States
James W. MacDonald49k wrote:

This is not the correct support site for ggplot2, which is a CRAN package. Try R-help or stackoverflow.

ADD COMMENTlink written 3.7 years ago by James W. MacDonald49k

Ok. Thanks.

 

ADD REPLYlink written 3.7 years ago by alakatos90
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 147 users visited in the last hour