ggplot2
. psmelt
relies heavily on the
melt
and merge
functions.
The naming conventions used in downstream phyloseq graphics functions
have reserved the following variable names that should not be used
as the names of sample_variables
or taxonomic rank_names
.
These reserved names are c("Sample", "Abundance", "OTU")
.
Also, you should not have identical names for
sample variables and taxonomic ranks.
That is, the intersection of the output of the following two functions
sample_variables
, rank_names
should be an empty vector
(e.g. intersect(sample_variables(physeq), rank_names(physeq))
).
All of these potential name collisions are checked-for
and renamed automtically with a warning.
However, if you (re)name your variables accordingly ahead of time,
it will reduce confusion and eliminate the warnings.psmelt(physeq)
otu_table-class
or
phyloseq-class
. Function most useful for phyloseq-class.data.frame
-class table.tip_glom
--
can help alleviate RAM usage problems.
This function is made user-accessible for flexibility,
but is also used extensively by plot functions in phyloseq.plot_bar
data("GlobalPatterns")
gp.ch = subset_taxa(GlobalPatterns, Phylum == "Chlamydiae")
mdf = psmelt(gp.ch)
nrow(mdf)
ncol(mdf)
colnames(mdf)
head(rownames(mdf))
# Create a ggplot similar to
library("ggplot2")
p = ggplot(mdf, aes(x=SampleType, y=Abundance, fill=Genus))
p = p + geom_bar(color="black", stat="identity", position="stack")
print(p)
Run the code above in your browser using DataLab