Hi,
I want to draw a barplot with basic ggplot
but I would like to color the bar in the plot (so genes) that have a specific value (e.g. above 1) with a different color from the other. I found this webiste where they show how to do it but I was wondering if there is a simple/faster way to do it without me going through the dataset and check which row has the value, I am interested and then change the name and so on.. since I am planning to do multiple barplots for multiple genes?
or if there is any other similar question that I might have missed on the web that could answer my question would be much appreciated.
here my code to generate a normal barplot only with one sample (just to give an idea):
#define new dataset
d1 <- mouse$`Log2FC p0`
x= mouse$GeneSymbl
#tell what to plot
to_plot <- data.frame(x=x, "Mouse"=d1)
melted<-melt(to_plot, id="x")
#plot
f <- ggplot(melted,aes(x=x,y=value,fill=variable)) + geom_bar(stat="identity", colour="black", size=0.4, width = 0.8, position="dodge", show.legend = T)+
labs(y="LOG2FC", x = "Genes shared", title ="Apoptotic genes comparion") + scale_fill_manual(values=c("blue"))
f + theme(legend.text=element_text(size=8), legend.title = element_blank(), legend.position="bottom", panel.background = element_blank(), axis.line = element_line(colour = "black"),axis.text.x = element_text(face="plain", color="black", size=9, angle=45, hjust=1), axis.text.y = element_text(face="plain", color="black", size=10, hjust=1))
I have also tried to assign a new column to "melted" dataset but it's not working at all, it doesn't ever show the bars to be blue (like in the previous example):
#define new dataset
d1 <- mouse$`Log2FC p0`
x= mouse$GeneSymbl
#tell what to plot
to_plot <- data.frame(x=x, "Mouse"=d1)
melted<-melt(to_plot, id="x")
melted[["sign"]] = ifelse(melted[["value"]] <= -1, "positive", "negative")
#plot
f <- ggplot(melted,aes(x=x,y=value,fill=variable)) + geom_bar(stat="identity", colour="black", size=0.4, width = 0.8, position="dodge", show.legend = T)+
labs(y="LOG2FC", x = "Genes shared", title ="Apoptotic genes comparion") + scale_fill_manual(values = c("positive" = "darkblue", "negative" = "red"))
f + theme(legend.text=element_text(size=8), legend.title = element_blank(), legend.position="bottom", panel.background = element_blank(), axis.line = element_line(colour = "black"),axis.text.x = element_text(face="plain", color="black", size=9, angle=45, hjust=1), axis.text.y = element_text(face="plain", color="black", size=10, hjust=1))
thank you very much
Camilla