Hello all!
I was wondering if you could help me construct a heat map using qiime2r. I have been using code from some of the other posts on here, but seem to need additional tweaking I cant figure out.
Here is the code I am using:
library(tidyverse)
library(qiime2R)
OTUs<-apply(OTUs.j, 2, function(x) x/sum(x)*100)
head(OTUs)
OTUs<-
data.frame(MeanAbundance=rowMeans(OTUs)) %>%
rownames_to_column("Feature.ID") %>%
arrange(desc(MeanAbundance)) %>%
top_n(30, MeanAbundance) %>%
pull(Feature.ID)
OTUs %>%
as.data.frame() %>%
rownames_to_column("Feature.ID") %>%
gather(-Feature.ID, key="SampleID", value="Abundance") %>%
mutate(Feature.ID=if_else(Feature.ID %in% OTUs, Feature.ID, "Remainder")) %>%
group_by("SampleID", Feature.ID) %>%
summarize(Abundance=sum(Abundance)) %>%
left_join(metadata) %>%
mutate(NormAbundance=log10(Abundance+0.01)) %>%
left_join(Taxonomy.j) %>%
mutate(Feature=paste(Feature.ID, Taxon)) %>%
mutate(Feature=gsub("[kpcofgs]__", "", Feature)) %>%
mutate('Period'=factor('Period',levels = c("A","B","C")))
ggplot(aes(x=Period
, y=Feature, fill=NormAbundance)) +
geom_tile() +
facet_grid(~Donor
, scales="free_x") +
theme_q2r() +
theme(axis.text.x=element_text(angle=45, hjust=1)) +
scale_fill_viridis_c(name="log10(% Abundance)")
ggsave("qiime2/image/heatmap.pdf", height=4, width=11, device="pdf")
here is the error I am stuck on:
Error in summarize()
:
! Problem while computing Abundance = sum(Abundance)
.
The error occurred in group 1: "SampleID" =
"SampleID", Feature.ID = "Remainder".
Caused by error in sum()
:
! invalid 'type' (character) of argument
Run rlang::last_error()
to see where the error occurred.
The OTUs 'type' is listed as a character in R. Does this need to be changed to a data frame ?
Thank you for your time in advance!