data(Tiahura)
## Compute dissimilary matrix from Jaccard's similarity coefficient:
tiah.jac <- dist.ldc(Tiahura$fish,method = "jaccard")
## Constrained clustering of the fish species:
tiah.chclust <- constr.hclust(tiah.jac, coords=Tiahura$habitat[,"distance"],
chron=TRUE)
## Plotting the results
par(mfrow=c(3,1))
## First graph: constrained clusters
par(mar=c(3,6.5,2,2))
dst <- Tiahura$habitat[,"distance"]
plot(NA, xlim=range(dst), ylim=c(0.5,5.5), yaxt="n",
ylab="Partitions\n\n", xlab="")
parts <- c(2,3,5,7,12)
cols <- c("turquoise", "orange", "chartreuse", "aquamarine", "blue",
"violet", "pink", "cyan", "green", "red", "cornsilk", "purple")
for(i in 1L:length(parts)) {
tiah.chclust$coords[,"y"] <- i
plot(tiah.chclust, parts[i], link=TRUE, lwd=3, hybrids="none",
lwd.pt=0.5, cex=3, pch=21, plot=FALSE,
col=cols[round(seq(1,length(cols), length.out=parts[i]))])
}
axis(2, at=1:length(parts), labels=paste(parts,"groups"), las=1)
## Second graph: transect profile
par(mar=c(4,6.5,1,2))
plot(x=dst, y=Tiahura$habitat[,"depth"],
ylim=c(max(range(Tiahura$habitat[,"depth"])),-300),
las=1, ylab="Depth\n(cm)\n", xlab="", type="l", lwd=2)
for(i in 1:nrow(Tiahura$reef)) {
abline(v=Tiahura$reef[i,2], lty=3)
abline(v=Tiahura$reef[i,3], lty=3)
if((Tiahura$reef[i,3] - Tiahura$reef[i,2])<100) {
text(x=(Tiahura$reef[i,2] + Tiahura$reef[i,3])/2, y=2350,
labels=toupper(Tiahura$reef[i,1]),srt=90,adj=0)
} else {
text(x=(Tiahura$reef[i,2] + Tiahura$reef[i,3])/2, y=-150,
labels=toupper(Tiahura$reef[i,1]))
}
}
## Third graph: bottom composition
par(mar=c(5,6.5,0,2))
plot(NA,xlim=range(dst), ylim=c(0,1), las=1,
ylab="Bottom composition\n(proportions)\n", xlab="Distance (m)")
bot <- cbind(0, Tiahura$habitat[,3:10])
for(i in 2:9) bot[,i] <- bot[,i] + bot[,i-1]
cols <- c("", "grey75", "brown", "grey25", "green", "purple",
"lightgreen", "yellow", "white")
for(i in 2:9)
polygon(x=c(dst, rev(dst)),y=c(bot[,i], rev(bot[,i-1]))/50,
col=cols[i])
text(x=c(44, 365, 707, 538, 957, 111, 965),
y=c(0.05, 0.47, 0.37, 0.58, 0.42, 0.80, 0.88),
labels=colnames(bot)[2:8], xpd=TRUE)
## Species presence graph set:
plot_slice <- function(sl,split) {
size <- ceiling(length(Tiahura$species)/split)
sp_slice <- size*(sl - 1L) + (1L:size)
image(z=t(as.matrix(Tiahura$fish[,sp_slice])),y=1:nrow(Tiahura$fish),
x=1:length(sp_slice),zlim=c(0,1),col=c("white","black"),axes=FALSE,
ylab="",xlab="")
axis(1L,at=1:length(sp_slice),labels=Tiahura$species[sp_slice],las=2L)
axis(2L,at=1:nrow(Tiahura$fish),label=rownames(Tiahura$fish),las=1L)
invisible(NULL)
}
par(mar=c(15,5,2,2))
plot_slice(1L,5L)
## plot_slice(2L,5L)
## plot_slice(3L,5L)
## plot_slice(4L,5L)
## plot_slice(5L,5L)
Run the code above in your browser using DataLab