### 1 样本物种注释后会得到各个水平的相对丰度表
## 种水平的相对丰度 物种注释
Samples sp1 sp2 sp3
S__Abiotrophia_defectiva 0 2.16456839333914e-06 0
S__Acetanaerobacterium_elongatum 1.05806590497696e-06 0 0
S__Acetitomaculum_ruminis 0 0 0
S__Acetivibrio_cellulolyticus 0 9.89868878213682e-06 0
S__Acetivibrio_ethanolgignens 2.54762969610528e-05 4.89713417844563e-05 1.68196117368884e-05
S__Acetoanaerobium_noterae 0 0 0
S__Acetoanaerobium_sticklandii 0 0 0
### 2 对数据进行处理,取前N优势物种
思路: ①对每个样本取前N优势物种,去重复,得到矩阵,再进行R 绘制图;② 对每个物种的所有样本求和,排序,前N的优势物种。
### 思路②
topNData = taxonomy[order(apply(data, 1, sum),decreasing = 1)[1:topN],]
others=1- apply(topNData, 2, sum)
others=as.data.frame(others)
topNData=rbind(topNData,t(others))
### 3 R绘图
## ggplot 很青睐 长格式的数据(melt)
ggplot(dataTM,aes(sample,value,fill=variable))+
guides(fill = guide_legend(keywidth = 0.8, keyheight = 0.8, title="type", size=5,ncol = 1 )) +
theme_bw()+geom_bar(stat="identity",position="stack")+
+theme_calc()+
ylab("Relative abundance")+xlab("Samples")