Hi, I am trying to create what are called "spider diagrams" in the
geochemical
literature using R. A spider diagram is basically a plot of the atomic number
versus the concentration on a log scale. Lines are drawn from each atomic
number for each sample.
Right now, my data frame looks like:
SAMPLE SITE V3 LA.NASC LAATNUM CE.NASC CEATMNUM
1 1A:001 ICU Loc 1A Kasori E 0.2708179 57 0.3285894 58
2 1A:002 ICU Loc 1A Kasori E 0.4542450 57 0.5353200 58
3 1A:003 ICU Loc 1A Kasori E 0.3020954 57 0.3330943 58
4 1A:004 ICU Loc 1A Kasori E 0.4956085 57 0.5660766 58
5 1A:005 ICU Loc 1A Kasori E 0.6821741 57 0.7434971 58
6 1A:006 ICU Loc 1A Kasori E 0.2667235 57 0.3471334 58
7 1A:008 ICU Loc 1A Kasori E 0.4072798 57 0.5160001 58
8 1A:011 ICU Loc 1A Kasori E 0.2958622 57 0.4187263 58
9 1A:017 ICU Loc 1A Kasori E 0.2479571 57 0.3287652 58
10 1A:018 ICU Loc 1A Kasori E 0.1469086 57 0.1802292 58
11 1A:019 ICU Loc 1A Kasori E 0.4560389 57 0.6020045 58
ND.NASC NDATNUM SM.NASC SMATNUM
1 0.3726716 60 0.3915657 62
2 0.6724895 60 0.6687707 62
3 0.4930570 60 0.4995848 62
4 0.6827095 60 0.6414732 62
5 1.1013142 60 1.3937307 62
6 0.4419258 60 0.3340616 62
7 0.6425135 60 0.4334365 62
8 0.4402632 60 0.2898625 62
9 0.3856467 60 0.2911848 62
10 0.1991619 60 0.1864905 62
11 0.7596844 60 0.7790251 62
My plotting commands:
plot(spider[,5],spider[,4],xlim=range(57,63),ylim=range
(0.1,10),log="y",pch=as.integer(spider[,1]))
points(spider[,7],spider[,6],pch=as.integer(spider[,1]))
points(spider[,9],spider[,8],pch=as.integer(spider[,1]))
points(spider[,11],spider[,10],pch=as.integer(spider[,1]))
Okay, sop far, so good. the problem I am having is getting the points
connected properly (based on the sample number). I need the lines going across
the plot, not parallel to the y-axis (which I have done all too easily).
Sorry to bother you folks with what is probably an easy question, but I've
reached the point of not sure what to try next. I have a suspicion this
is something readily done in R though...
Are there any people out there using R for geochemical data?
Best, Mark Hall
markhall at gol.com
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._