Dear Mark,
A friend of mine, who is on r-help disscusion group has forwarded me your
querry regarding the spiderplots.
I am very much using R for geochemical calculations (mainly WR geochemistry
of igneous rocks, plus radiogenic isotopes). OC I did need to solve the
problem with spiderdiagrams and here are fragments of my code. I trust they
will be of help:
# normalization (A,B)
# Normalizes data for a spiderdiagram
#
# Parameters:
# sample analyses [A]
# normalizing values [B]
#
normalization<-function(A,B){
C<-matrix(rep(NA,nrow(A)*length(B)),ncol=length(B))
for (i in 1:nrow(A)){
C[i,]<-A[i,]/B
}
dimnames(C)<-dimnames(A)
return(C)
}
# spiderplot (A,B,model,ymin,ymax,add)
# Plots spiderdiagram
#
# Parameters:
# normalized values [A]
# normalizing values [B]
# range of the diagram [ymin, ymax]
# shall be the patterns unbroken even for missing values (join)
spiderplot<-function(A,B,ymin,ymax,join=T){
if (ymin<=0) {ymin<-min(A,na.rm=TRUE)/10}
if (ymax<=ymin) {ymax<-10*max(A,na.rm=TRUE)}
windows(width = 8, height = 6.5, pointsize = 12)
plot(A[1,],pch=1,xlab="",type="n",log="y",ylim=c(ymin,ymax),axes=FALSE,ylab="")
axis(1, 1:length(B),labels=colnames(A))
axis(2,)
for (i in 1:nrow(A)){
points(A[i,],pch=i)
tempy<-A[i,][!is.na(A[i,])]
tempx<-(1:length(B))[!is.na(A[i,])]
if (join){
lines(tempx,tempy)}
else{
lines(1:length(B),A[i,])}
}
}
#X is a numeric data matrix with data you need to normalize, samples in
rows, elements in columns
# chondrit is a numeric vector with the normalizing values
Y<-normalization(X,chondrit)
spiderplot(Y,chondrit,1,1000)
My test data:
X:
La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho Er Tm Yb
Sa-3 47.44 96.08 NA 45.15 NA 7.98 1.82 NA NA 5.22 1.13 2.72 NA 2.95
Sa-4 21.67 71.78 6.94 29.71 NA 6.24 1.50 6.09 0.92 5.80 1.03 2.80 0.43 2.88
Sa-7 20.76 42.02 4.96 17.44 NA 3.76 1.77 3.76 0.56 2.70 0.56 1.64 0.24 1.52
Lu
Sa-3 0.29
Sa-4 0.43
Sa-7 0.25
chondrit (REE in chondrites according to Boynton 1984)
La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho
0.3100 0.8080 0.1220 0.6000 1.0000 0.1950 0.0735 0.2590 0.0474 0.3220 0.0718
Er Tm Yb Lu
0.2100 0.0324 0.2090 0.0322
I trust this will work for you. Please send any comments to my private
email address since I am not on this discussion group (yet?).
Best regards,
Vojtech
dr. Vojtech Janousek
------------------------------------------------------------------
Snail-mail:
Czech Geological Survey telephone: (420) (2) 510 85 308
Klarov 3 fax: (420) (2) 581 87 48
118 21 Prague 1
Czech Republic
http://www.geocities.com/vjanousek.geo/
ICQ 32744555
-------------------------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._