练习题六:微生物物种分布柱状图
mycol <-c(119,132,147,454,89,404,123,529,463,104,552,28,54,84,256,100,558,43,652,31,610,477,588,99,81,503,562,76,96,495)
mycol <-colors()[rep(mycol,20)]
otu <-read.table(file="genus.xls",header=T,check.names=FALSE,sep="\t")
rownames(otu) <- otu[,1]
otu <-otu[,-1]
al <- which(rownames(otu) %in% c("All"))
if(length(al)) otu <-otu[-al,]
rowsum <-sapply(1:nrow(otu),function(x) sum(otu[x,]))
otu<-otu[order(rowsum,decreasing=TRUE),]
dat <-sapply(1:ncol(otu),function(x) otu[,x]/sum(otu[,x]))
colnames(dat) <-colnames(otu)
rownames(dat) <-rownames(otu)
lab <-rownames(dat)
tiff(file="bar.genus.tiff",width=750,height=700,pointsize=15) ###pdf(file="bar.genus.pdf", height=8,width=7)
layout(matrix(1:2,2,1),heights=c(1:1.2))
par(mar=c(3,5,2,2))
barplot(dat*100,width=1,space=1.2,plot=T,las=1,col=mycol[1:nrow(dat)],cex.axis=1,cex.names=1,border=NA,ylab="Relative abundance(%)",offset=0,cex.lab=1.2)
par(mar=c(2,5,1,1))
plot.new()
legend("topleft",legend=rownames(dat),ncol=3,fill=mycol[1:nrow(dat)],cex=0.8,bty="n")
dev.off()
*
2021-10-22 23:28:38
3.83MB
R语言
1