Skip to content

Instantly share code, notes, and snippets.

@geneva
Created February 5, 2011 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save geneva/812820 to your computer and use it in GitHub Desktop.
Save geneva/812820 to your computer and use it in GitHub Desktop.
Reads TA data and plots piechart and chao1/rarefaction line graphs3
library(vegan)
class <- "Anthony"
dat <- read.table(paste(class,".dat", sep=""), sep = "\t", header=TRUE)
#######PieChart############
piedata <- matrix(ncol=1, nrow=length(unique(dat[,1])))
names <- levels(unique(dat[,1]))
rownames(piedata) <- names
######Total number of morphospecies per order#####
for (i in 1:length(names)){
sum <- 0
for (j in 1:nrow(dat)){
if (dat[j,1]==names[i])
{sum <- sum + 1}
}
piedata[i] <- sum
}
#####Total number of insects per order#########
#for (i in 1:length(names)){
# sum <- 0
# for (j in 1:nrow(dat)){
# if (dat[j,1]==names[i])
# {sum <- sum + dat[j,(ncol(dat))]}
# }
# piedata[i] <- sum
#}
pdf(file=paste(class,"_pie.pdf", sep=""))
pie(piedata, labels = rownames(piedata), col=rainbow(nrow(piedata)), main=paste(class,"'s class",sep=""))
dev.off()
###########Rarefaction and Chao############
tdat <- t(dat[3:(ncol(dat)-1)])
### create a matrix of chao and rarefyed data #######
#rdat <- rrarefy(tdat, (nrow(tdat)))
pdf(file=paste(class,"_chao.pdf", sep=""))
plot(specaccum(tdat)$sites, specaccum(tdat)$richness, ylim=c(0,300), ylab="# of Morphospecies", xlab="# of Group Samples", type="b", pch=1, col=2, cex=2, cex.lab=1.5, main=paste(class,"'s class",sep=""))
chao <- matrix(ncol=2, nrow=nrow(tdat))
for (i in (nrow(tdat)):1)
{
chao[i,2] <- specpool(tdat[1:i,])$chao
chao[i,1] <- i
}
lines(chao, lty=2, type="b", pch=0, col=4, cex=2)
legend("topright", legend=c("Observed", "Chao1"),lty=c(1,2), pch=c(1,0), col=c(2,4))
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment