Hi friends I am using phyloseq R package to visualise MOTHUR output files. I am using the following code to generate stacked barplot at the phylum level.
But I can't understand how to order the x-axis either alphabetically (controls and test) or increasing or decreasing order (when numerical). Also, I'm not clear regarding the function of "labels" and "breaks" parameter.
#There is five taxa in this dataset at the phylum level. So we only need five colors for displaying them.
phylum_colors <- c("steelblue", "red", "orange","magenta", "maroon")
#Using these five colors we can now plot the bargraph.
ggplot(mdata_phylum, aes(x = Sample, y = Abundance, fill = Phylum)) +
#facet_grid(time~.) +
geom_bar(stat = "identity") +
scale_fill_manual(values = phylum_colors) +
scale_x_discrete(
breaks = map$sample,
labels = map$bodyweight,
drop = FALSE
) +
# Remove x axis title, and rotate sample lables
theme(axis.title.x = element_blank(),
axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) +
# additional stuff
guides(fill = guide_legend(reverse = TRUE, keywidth = 1, keyheight = 1)) + # modifying the legend
ylab("Relative Abundance (Phyla > 1%) \n") +
ggtitle("Phylum Composition of Mothur MiSeq SOP data per individual")
Here's first few lines of my data :
head(mdata_phylum)
OTU Sample Abundance sample type time bodyweight Kingdom Phylum
1 Otu00009 DRR046797 0.13355032 DRR046797 control early 20 k__Bacteria p__Actinobacteria
2 Otu00009 DRR046803 0.12054269 DRR046803 obese late 45 k__Bacteria p__Actinobacteria
3 Otu00009 DRR046802 0.09081125 DRR046802 obese late 45 k__Bacteria p__Actinobacteria
4 Otu00009 DRR046805 0.08990834 DRR046805 obese early 78 k__Bacteria p__Actinobacteria
5 Otu00009 DRR046798 0.08933365 DRR046798 control early 40 k__Bacteria p__Actinobacteria
6 Otu00009 DRR046801 0.07269419 DRR046801 obese late 45 k__Bacteria p__Actinobacteria
Can anyone please help me?
Thanks and Regards, DC7
so, should the label and breaks be same?
breaks - the positions in your data, for instance if x is 1-9 you can have breaks at `c(1,3,5,7,9). Labels - whatever you want to write on the plot in those breaks. They are not the same (they could though)
ok sir. Thanks. Now I understand