library('tidyverse')
library('reshape2')
l <-c('Phylum','Order','Genus','Species')
h <- 'f://'
f<-function (h,m){
data <-readxl::read_xlsx(paste("F://",m,".xlsx",sep=''))
b <- melt(data,variable.name ='Taxa')
c <- b[[m]]
fil <-c('#FF0000','#008B00','#FFD700','#9400D3','#00BFFF','#C1CDCD','#66CDAA','#000080','#DB7093','#C6E2FF',
'#EEEE00','#9FB6CD','#00FF7F','#4682B4','#912CEE','#EEE5DE','#FFDAB9','#96CDCD','#9AFF9A','#FF8C69','#EEE8AA','#1C1C1C')
ggplot(b) +
geom_bar( mapping = aes(x = c, y=value, fill=Taxa,color=fil)
,stat = "identity", width=0.87, col='black',position='fill')+
facet_grid(.~ID,scales='free',space='free')+
theme_bw() +
theme(axis.text.x = element_text(face = "bold", vjust = 0.5, hjust = 0.5,angle = 45),text=element_text("serif"),legend.position = 'none') +
scale_fill_manual(values= fil)+
xlab(m)+
ylab('Relative abundance')
guides(fill = guide_legend(ncol=1))
ggsave(filename = paste(h,m,'.png',sep='') , height=8, width=8, units = 'in', dpi=300)
}
for (m in l){
f (h,m)
print(m)
}
