[R] Mapping PCA loadings on to map
Laura Quinn
laura at env.leeds.ac.uk
Wed Aug 25 14:12:04 CEST 2004
Hello all,
I have performed PCA on stacked wind vector data for 20 different spatial
locations. In this case I therefore am in effect working out a PCA for 40
different stations (2 paired pieces of information [ie u and v vector
information] for each station), so have 40 PCs.
In my previous PCA (for none vector data) i have plotted the PC loadings
onto a map of the area of concern, and would like to represent
the results of this PCA in a similar way.
My previous code looks like this:
east<-sort(unique(alt$east))
north<-sort(unique(alt$north))
map.matrix<-matrix(alt$Alt,nrow=length(north),byrow=TRUE)
site.data<-read.table("siteinfo.dat",header=TRUE)
ts.data<-read.table("met.dat",header=TRUE)
library(mva)
met.pca<-prcomp(ts.data,retx=FALSE,scale=TRUE,center=TRUE)
scale<-2
for(i in 1:4){
image(east,north,t(map.matrix),col=terrain.colors(50),axes=TRUE,
xlab="",ylab="")
text(site.data$east,site.data$north,labels=as.character(site.data$site))
pc<-met.pca$rotation[,i]
pc.pos<-(pc>0)
if(any(pc.pos)){
symbols(site.data$east[pc.pos],site.data$north[pc.pos],
circles=scale*pc[pc.pos],lwd=2,fg="red",inches=FALSE,add=TRUE)}
if(any(!pc.pos)){
symbols(site.data$east[!pc.pos],site.data$north[!pc.pos],
circles=-scale*pc[!pc.pos],lwd=2,fg="blue",inches=FALSE,add=TRUE)}
box()
}
My problem is, how can i adjust this code so that I get a pair of loadings
at each site? I've been having real problems trying to sort the
subscripting out, as i need to be able to recognise the PC loadings as
pairs, (so have made a further u and v subscript to each station name
before the analysis) but then I they aren't in the same format as needed
to plot onto the map.
I guess there is probably a very obvious way around this and would be
extremely grateful if anyone could help me out!
Also, it occurs to me that another way of representing this information is
by using the arrows() function to add a vector to the map - but again this
relies on my subscripting problem
TIA,
Laura
Laura Quinn
Institute of Atmospheric Science
School of the Environment
University of Leeds
Leeds
LS2 9JT
tel: +44 113 343 1596
fax: +44 113 343 6716
mail: laura at env.leeds.ac.uk
More information about the R-help
mailing list