Problems with relative abundance graphs

18 views
Skip to first unread message

md.genmicro

unread,
Nov 29, 2016, 3:36:41 PM11/29/16
to ggplot2
Hello everybody,

I´m struggling to fix the scale of my relative abundance graph with ggplot2 for a phyloseq class object. 
The script I´m using is:

#Calculating relative abundance for the whole set and selecting top5 classes:
dataf
datag = tax_glom(dataf, "Rank4") 
datarg = transform_sample_counts(datag, function(x) x/sum(x)) 
class.sumf = tapply(taxa_sums(datarg), tax_table(datarg)[, "Rank3"], sum, na.rm = TRUE)
top5fclass = names(sort(class.sumf, TRUE))[1:5]
top5f = prune_taxa((tax_table(datarg)[, "Rank3"] %in% top5fclass), datarg)


#Subsetting samples (I have 4 groups)

groupf1 = subset_samples(top5f, Group == "1" )
groupf1m = merge_samples(groupf1, group = "Date", fun=mean)
pf1 = plot_bar(groupf1m, "Rank3", fill = "Rank3", facet_grid =~~ sample_names(groupf1m), title = "X1" ) + scale_fill_brewer(palette = "Set2") + guides(fill=FALSE) + xlab("Class") + ylab("Relative Abundance") + guides(fill=FALSE)
pf1 = pf1 + geom_bar(stat="identity") 
pf1  

#Multiple plot

require(cowplot)
theme_set(theme_cowplot(font_size=8))
pf = plot_grid(pf1, pf2, pf3, pf4, ncol = 2, align = 'h')
pf 

#Results:
 My result is a multiple grid, with different scales, with numbers that doesn´t make much sense for me (like from 0 to 4 in one grid, the other from 0 to 2)... when I try to put everything in the same scale with ylim, some bars disappear... besides that, the sum of all bars (for each group) is larger than 1. 

If anyone have an idea of what I can do to fix, I ´ll appreciate very much! If you have any comment to improve this script (I´m a beginner), it´s also great!

Thanks in advance!
Reply all
Reply to author
Forward
0 new messages