On 06/30/2011 05:37 AM, chris20 wrote:
Hi,

I am trying to put together a biplot using symbols and different colours
instead of text as points.

Someone has previously suggested using this code:

PC<- prcomp (iris[,1:4])
lambda<- PC$sdev * sqrt(nrow(PC$x))
plot (t(t(PC$x)/lambda),pch=16,col=as.numeric(iris[,5]))
par (new=T)
Rot<- t(t(PC$rotation)*lambda)
XLIM<- c(-max(abs(Rot[,1])),max(abs(Rot[,1])))
XLIM<- XLIM+(XLIM*0.7)
plot(Rot,col=4,axes=FALSE,xlim=XLIM,ylim=XLIM,pch="")
arrows
(rep(0,nrow(PC$rotation)),rep(0,nrow(PC$rotation)),Rot[,1],Rot[,2],col=4)
text (Rot[,1:2],rownames(Rot),col=6)
axis (3)
axis (4)

But the origin of the arrows does not line up with the origin of the points.
Can anyone suggest how you would get the two graphs to line up?  I think you
have to set a ratio between the two sets of axes so that the origin is in
the centre but I don't know how to do it.

Hi Chris,
In order to get the zeros of the two abscissae at the same horizontal point, you will have to make both symmetric. Change your third like to:

plot(t(t(PC$x)/lambda),pch=16,col=as.numeric(iris[,5]),
 xlim=c(-0.15,0.15))

and see what happens.

Jim

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to