15.3.1 Hierarchical Methods

# Fig. 15.1.: Hierarchical methods
library(StatDA)
pdf("fig-15-1.pdf",width=8,height=6)
par(mar=c(1,4,3,1))
data(chorizon)
el=c("Na","Ca","K","Al")
x=chorizon[,el]
sel=((chorizon[,"LITO"]==9) | (chorizon[,"LITO"]==82))
x=scale(log10(x[sel,]))
lab=chorizon[sel,"LITO"]
lab.new=lab
lab.new[lab==82] <- "Alk"
lab.new[lab==9] <- "Sed"
par(mfrow=c(3,1))
plot(hclust(dist(x),method="average"),labels=lab.new,sub="",main="Average linkage",
xlab="")
abline(h=3.6,lty=2,lwd=1.5)
plot(hclust(dist(x),method="complete"),labels=lab.new,sub="",main="Complete linkage",
xlab="")
abline(h=5.3,lty=2,lwd=1.5)
plot(hclust(dist(x),method="single"),labels=lab.new,sub="",main="Single linkage",
xlab="")
abline(h=2.35,lty=2,lwd=1.5)

dev.off()
# Fig. 15.2.: Hierarchical methods - result
library(StatDA)
data(chorizon)
data(kola.background)

el=c("Na","Ca","K","Al")
x=chorizon[,el]
sel=((chorizon[,"LITO"]==9) | (chorizon[,"LITO"]==82))
x=scale(log10(x[sel,]))
lab=chorizon[sel,"LITO"]
lab.new=lab
lab.new[lab==82] <- 1
lab.new[lab==9] <- 3
set.seed(100)
res=hclust(dist(x),method="average")
cl=cutree(res,2)
cl.new=cl
cl.new[cl==2] <- 1
cl.new[cl==1] <- 3

X=chorizon[,"XCOO"]
Y=chorizon[,"YCOO"]
# true representation of x and y axis of map for plot
xwid=diff(range(X))/12e4
ywid=diff(range(Y))/12e4
pdf("fig-15-2.pdf",width=2*xwid,height=1*ywid)
par(mfrow=c(1,2),mar=c(1.5,1.5,1.5,1.5))

# NEW MAP
plot(X,Y,frame.plot=FALSE,xaxt="n",yaxt="n",xlab="",ylab="",type="n")
plotbg(map.col=c("gray","gray","gray","gray"),add.plot=T)
points(chorizon[sel,"XCOO"],chorizon[sel,"YCOO"],col=1,pch=lab.new)

# Legend
text(752000,7880000,"Lithologies",cex=1)

# scalebar
scalebar(761309,7373050,861309,7363050,shifttext=-0.5,shiftkm=37e3,sizetext=0.8)
# North arrow
Northarrow(362602,7818750,362602,7878750,362602,7838750,Alength=0.15,Aangle=15,Alwd=1.3,Tcex=1.6)



# NEW MAP
plot(X,Y,frame.plot=FALSE,xaxt="n",yaxt="n",xlab="",ylab="",type="n")
plotbg(map.col=c("gray","gray","gray","gray"),add.plot=T)
points(chorizon[sel,"XCOO"],chorizon[sel,"YCOO"],col=1,pch=cl.new)

# Legend
text(752000,7880000,"Average linkage",cex=1)

# scalebar
scalebar(761309,7373050,861309,7363050,shifttext=-0.5,shiftkm=37e3,sizetext=0.8)
# North arrow
Northarrow(362602,7818750,362602,7878750,362602,7838750,Alength=0.15,Aangle=15,Alwd=1.3,Tcex=1.6)

dev.off()