Question: mothur output visualisation with Phyloseq: unable to order the x-axis
0
gravatar for dpc
8 months ago by
dpc150
India
dpc150 wrote:

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

phyloseq mothur 16s R • 233 views
ADD COMMENTlink modified 8 months ago by Asaf8.5k • written 8 months ago by dpc150
0
gravatar for Asaf
8 months ago by
Asaf8.5k
Israel
Asaf8.5k wrote:

You will have to order the dataframe before plotting. Take a look at this thread on SO: https://stackoverflow.com/questions/3253641/order-discrete-x-scale-by-frequency-value there are several solutions.

breaks will define where there will be a tick on the axis, it's more useful when it's continuous, labels are the labels that will displayed on those ticks (or breaks).

Another note if I may, it's best to select colors from a pre-defined palette like RColorBrewer, you can select the dark2 palette for instance using: phylum_colors <- brewer.pal(5, "Dark2")

ADD COMMENTlink written 8 months ago by Asaf8.5k

so, should the label and breaks be same?

ADD REPLYlink written 8 months ago by dpc150

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)

ADD REPLYlink written 8 months ago by Asaf8.5k

ok sir. Thanks. Now I understand

ADD REPLYlink written 8 months ago by dpc150
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1158 users visited in the last hour
_