Hello,
I want to compare two groups that share the same row names. I did order using one of the numeric variables in the data frame. However, the plot appeared as if the order was not done. See below the code I used to create the simulation dataset and how I run it. Please I may ask your feedback on how I can do it better to get an ordered bar graph?
Thank you.
data <- data.frame(pathway = c(
"cGMP-PKG",
"Human infection",
"Apelinhway",
"Ribosome",
"HIF-1",
"Carbon metabolism",
"Purine metabolism",
"Cholinergic synapse",
"ErbB",
"Cysteine",
"Valine",
"Human infection",
"Apelinhway",
"cGMP-PKG",
"Purine metabolism",
"Ribosome",
"Carbon metabolism",
"Cholinergic synapse",
"ErbB",
"HIF-1",
"Valine",
"Cysteine"),
logFC = runif(22, -1, 1),
pvalue = runif(22, max= 0.05, min= 0.001),
count = c(7,12,19,12,34,8,5,4,7,9,20,32,4,7,9,10,22,3,5,8,9,10),
group = rep(c("WT","KO"), each = 11))
data_order <- data[order(data$count, decreasing = TRUE),]
library(ggplot2)
library(dplyr)
data_order %>%
ggplot(aes(x = pathway, y = count, fill = group)) +
geom_bar(stat = "identity", position = position_dodge())+
coord_flip() +
theme(axis.title=element_text(size=10,face="bold"),axis.text = element_text(size = 10),title=element_text(size=8,face="bold"))+
ylab("Number of genes") + xlab("Pathway Names") +
ggtitle("Regulated")