This is a test version of Biostars. For the public version, visit https://www.biostars.org.
2 stages of GeneOntology in the same figure

I have 2 set of genes that are enriched at different development stages. I have visulaized their GeneOntology individually using ggplot.

Now I would like to put the geneontology visulization in the same figure. For example: stage 1 on the leftside, stage2 at the right side. The bars are horizontal. They share Y axis but using two parts of the X axis.

I have searched a round. Maybe because my expression in google in not accurate most of the questions and answers I searched does not fit my question.

Does anyone know where I can look into?

Thank you very much

r next-gen gene

1 answer

You want either facet_wrap or facet_grid, depending on how your data is structured.

Thank you for the advice. My data is like this: (Term)/(Count)/(PValue)/(Genes) /(List _Total)/(Pop_Hits)/(Pop_Total)/(Fold_Enrichment)/ (Bonferroni)/(Benjamini)/(FDR)/( Group)

it is a csv file and contains the above columns (I listed the columns and separate them by using / ). My original code is:

mydata_2 <- subset(mydata, mydata$PValue < 0.01)  #select based on Pvale<0.01
mydata_3 <- mydata_2 %>% mutate(Term = fct_reorder(Term, logPValue)) #reorder the Term based on logPValue
#mydata_4 <- mydata_2 %>% mutate(Term = fct_reorder(Term, desc(logPValue))) #reorder it in the other way
p <- ggplot(data=mydata_3, aes(x=Term, y=logPValue), size =1) + geom_bar(position = 'dodge', stat='identity', fill = "red") +geom_text(aes(x = Term, y = logPValue,label=Count), hjust = -0.5, size = 3, inherit.aes = TRUE)
p 
p+coord_flip() +theme_bw() +theme(panel.border = element_blank(), panel.grid.major = element_blank(),
                                  panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"))

I added a group column in mydata_3 and label each row that belong to group 1 (contains first 20 rows), or group2(contains 21 rows). I want to put the geneontology and P value side by side separated by group factor. But do not know how to modify my code

Should be able to just add + facet_wrap(vars(Group)) to your last line and get what you want.

It gives me 2 groups indeed. However, the two groups are on the same side of the Y axis with one column is group1 the the other column right to it was group2 (Both groups are on the right side of Y axis). But it is a good start.

I eventually found how to express my question: I would like to make a divergent barplot with ggplot2. I have found some posts and learn it.

Thank you for your help,

Log in to answer this question.