15.6 Selection of Variables for Cluster Analysis

# Fig. 15.9.: Variable clustering
library(StatDA)
data(kola.background)

data(ohorizon)
el=c("Ag","Al","As","Ba","Bi","Ca","Cd","Co","Cr","Cu","Fe","Hg","K",
"La","Mg","Mn","Mo","LOI","Na","Ni","P","Pb","Rb","S","Sb","Si","Sr","Th",
"Tl","U","V","Y","Zn")
x=scale(log10(ohorizon[,el]))

set.seed(100)
resvarall=Mclust(x,3:6)

X=ohorizon[,"XCOO"]
Y=ohorizon[,"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-9.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)

resvaral <- resvarall$cl
resvaral[resvarall$cl==1] <- 2
resvaral[resvarall$cl==2] <- 3
resvaral[resvarall$cl==3] <- 4
resvaral[resvarall$cl==4] <- 16
resvaral[resvarall$cl==5] <- 1
resvaral[resvarall$cl==6] <- 15

points(ohorizon[,"XCOO"],ohorizon[,"YCOO"],pch=resvaral,cex=0.8)

# Legend
text(752000,7880000,"All variables",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)

el=c("Cu","Co","Ni")
x=scale(log10(ohorizon[,el]))
set.seed(100)
resvarsel=Mclust(x,3:3)

# 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)

resvarse <- resvarsel$cl
resvarse[resvarsel$cl==1] <- 1
resvarse[resvarsel$cl==2] <- 3
resvarse[resvarsel$cl==3] <- 15

points(ohorizon[,"XCOO"],ohorizon[,"YCOO"],pch=resvarse,cex=0.8)

# Legend
text(752000,7880000,"Co, Cu, Ni",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()