'in R Phyloseq package, How can I sort my sample data numerically in a heatmap?

I have a phyloseq object in R, that includes a dataframe of my environmental sample variables, one of these variables is a numerical data called "MBT5ME" and I want them to be shown in the heatmap ascending or descending not randomly, which seems to be the case everytime I plot the heatmap,

when I look at my sample data before I make my phyloseq object, they look ascending, but then when I plot, it doesn't.

here's my code:

library("phyloseq")
library("ggplot2")
library("readxl")
library("gridExtra")
library("vegan")
library("dplyr")
library("tibble")

WP1 <- phyloseq(OTU, TAX, samples)

WP1.4_trim <- prune_taxa(keepTaxa,WP1.4)
plot_heatmap(WP1.4_trim, "PCoA", distance="bray", 
             sample.label="MBT5ME", taxa.label="Phylum", low="palegreen", high="palegreen4", na.value="white")

Heatmap WP1.4trim

Does anyone know how to make the heatmap X axis "MBT5ME" appear in order from lowest value to highest? in this sense, also if I can make my y axis the bacteria "Class" appear also in alphabetical order?

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source