using qiime2 artifacts to create a relative abundance plot in rstudio

Hello everyone,

I am new to programming and Rstudio.

I am working on an environmental microbiome project, studying bacterial communities cultured from sediment core near an oil spill in Bemidji, Minnesota.

I would like to use qiime2 artifacts from my data set to produce a stacked relative abundance bar chart by phylum. Except I would like one phylum to be further divided into smaller taxa. Specifically, I would like to divide my Proteobacteria phylum divided in to alpha, beta, gamma, and delta Proteobacteria on the bar chart. Attached are my preliminary results.

I would also like to change the color of each bacteria type, so the neighboring bacteria on the chart are a starkly different color, rather than being represented by an indistinguishable gradient.

Thanks so much for your help:))
Aurora

I figured it might be helpful if I included the code I used to produce the attached rel abundance stack bar plot in my previous post:

library(phyloseq)
###tools>install packages>devtools
#devtools::install_github("jbisanz/qiime2R")
#BiocManager::install("Rtools")
library(qiime2R)
library(tidyverse)
library(vegan)
library(picante)
library(cowplot)
library(DESeq2)
library(ggplot2)
###tools>install packages>picante
###tools>install packages>cowplot
###tools>install packages>ggplot2
#BiocManager::install("DESeq2")
###change working directory>more>go to working directory> r studio
###manually move all files (in next command) to r studio
phy <- qza_to_phyloseq (features = "DOC_ASV_taxo_contaminants_removed-table.qza", "DOC-taxonomy.qza", tree = "DOC-rooted-tree.qza", metadata = "DOC_map_contaminants_removed.tsv")
###manually move file shannon_vector.qza to r studio
###to see new file created "phy" go to environment tab
shannon <- read_qza("shannon_vector.qza")
rich <- plot_richness(phy)
###highlight only rich and press command enter
nsamples(phy)
sample_names(phy)
OTUtable<-otu_table(phy)
OTUtable<-as.data.frame(OTUtable)
write.csv(OTUtable,"OTU_table.csv")
rich
###pick up at line 199 in tutorial###
phy_rel_abund <- transform_sample_counts(phy, function(x) {x / sum(x)})
plot_bar(phy_rel_abund, fill = "Phylum") +
geom_bar(aes(color = Phylum, fill = Phylum), stat = "identity", position = "stack") +
labs(x = "", y="Relative abundance") +
theme_q2r() +
ggtitle("Relative abundance stack bar plot by Treatment") +
theme(axis.title = element_text(color="black", face="bold", size=10)) +
theme(plot.title = element_text(color="black", face = "bold", size =12, hjust = 0.5))

You need select a specific values of color for make better the plot.

For bettey hepl you, is necesary put some example about her data. dput()

Toy data

library (ggplot2)
Tratamiento = factor(c(1,2,1,2,1,2),labels=c("Testigo", "Tratado"))
Color = factor(c(1,1,2,2,3,3),labels=c("Verde","Envero","Negra"))
Aceitunas = c(72,33,11,8,17,59)

df=data.frame(Tratamiento,Color,Aceitunas) 
df

ggplot(data=df, aes(x=Tratamiento, y=Aceitunas, fill=Color)) + 
    geom_bar(stat="identity") +
    scale_fill_manual(values=c("#805115", "#FFE9AA","#8F305B"))

wiht scale_fill_manual() you could select the value of color. But you must select the same number of colors according to your fill variable.

In this link you can select the color tha you like
Pallet for select color

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.