Hello,
I am following the DeSeq2 tutorial in Phyloseq and I'm using the following code to plots OTUs by Genus, coloured by Order. I am doing multiple plots, which I want to then group together and the problem is that because some have different Orders included there is no colour consensus over the plots, for example so all Bacteroidales points are always red . Im struggling to find an answer to this?
library("ggplot2")
theme_set(theme_bw())
scale_fill_discrete <- function(palname = "Set1", ...) {
scale_fill_brewer(palette = palname, ...)
}
# Order order
x = tapply(sigtab$log2FoldChange, sigtab$Order, function(x) max(x))
x = sort(x, TRUE)
sigtab$Order = factor(as.character(sigtab$Order), levels=names(x))
# Genus order
x = tapply(sigtab$log2FoldChange, sigtab$Genus, function(x) max(x))
x = sort(x, TRUE)
sigtab$Genus = factor(as.character(sigtab$Genus), levels=names(x))
ggplot(sigtab, aes(x=Genus, y=log2FoldChange, color=Order)) + geom_point(size=6) +
theme(axis.text.x = element_text(angle = -90, hjust = 0, vjust=0.5))
Dot_plot_UN_LS1 <- ggplot(sigtab, aes(x=Genus, y=log2FoldChange, color=Order)) + geom_point(size=6) + theme(axis.text.x = element_text(angle = -90, hjust = 0, vjust=0.5))
Dot_plot_UN_LS1 + ggtitle("Differentially abundant OTUs (uninfected vs LS 1)") + theme(plot.title = element_text(size = 10, face = "bold"))
Any help appreciated,
Cheers,
Sarah
I'm not sure the answer, but it's more of a ggplot2 question than a DESeq2 one, so I'm removing the DESeq2 tag.
If I understand your question correctly, I believe the following link may provide a strategy.
http://stackoverflow.com/questions/6919025/how-to-assign-colors-to-categorical-variables-in-ggplot2-that-have-stable-mappin