I have a really basic phyloseq question which I annoyingly am unable to resolve.
I have a phyloseq object (OTU table, taxonomy, and sample data) with 4 sample variables like this
- Sample Data: [16 samples by 4 sample variables]
-
<code> type Plot host_species block</code><code> type Plot host_species block </code>
type Plot host_species block
I have done a transformation of sample counts, agglomeration and a psmelt:
#Genus1pct root
ps.rel3 = transform_sample_counts(ps.root, function(x) x/sum(x)*100)
# agglomerate taxa
glom3 <- tax_glom(ps.rel3, taxrank = 'Genus1pct', NArm = FALSE)
ps.melt3 <- psmelt(glom3)
in order to do a stacked barchart of my 16 samples here, divided by the three host species (Dryas, Salix, and Kobresia):
#level_order <- factor(species, c(')))
ggplot(ps.melt3, aes(x = Sample, y = Abundance, fill = Genus1pct)) +
geom_bar(stat = "identity", aes(fill=Genus1pct)) +
labs(x="", y="%",title = "Roots") +
facet_wrap(~sample_species, scales= "free_x", nrow=1) +
theme_bw() +
theme(legend.position = "right",
strip.background = element_blank(),
axis.text.x.bottom = element_blank(),
axis.ticks.x.bottom = element_blank())
However, I would like to do a stacked barchart with relative abundances by my three host species now.
How do I do this? I am basically looking for something like a transform_sample_counts-function just for sample variables. (This must, of course, be able to account
This is a (hapless) ggplot just plotting the host_species as x, without having done the transformation:
There are 5,6 and 5 samples on each of the three host species, and obviously I would like this plot here with even heights summing to a 100%.