[R] reflecting a PCA biplot

Allan Engelhardt (CYBAEA) allane at cybaea.com
Tue Aug 9 18:14:03 CEST 2011


Something like

opar<- par(mfcol = c(1, 2))
z<- prcomp(USArrests, scale = TRUE)
biplot(z, cex = 0.5)
z$x[,1]<- -z$x[,1]
z$rotation[,1]<- -z$rotation[,1]
biplot(z, cex = 0.5, xlab = "-PC1")
par(opar)


perhaps?

Allan


On 09/08/11 13:57, Andrew Halford wrote:
> Hi Listers,
>
> I am trying to reflect a PCA biplot in the x-axis (i.e. PC1) but am not
> having much success. In theory I believe all I need to do is multiply the
> site and species scores for the PC1 by -1, which would effectively flip the
> biplot.
>
> I am creating a blank plot using the plot command and accessing the results
> from a call to rda. I then use the calls to scores to obtain separate site
> and species coordinates and I have worked out how to multiply the
> appropriate PC1 scores by -1 to create the site and species scores I want.
> However I am not sure how to change the call to plot which accesses the
> results of the call to rda to draw the blank plot. The coordinates it is
> accessing are for the unreflected ordination and this does not match the new
> site and species scores that I have.
>
>
>> fish.pca<- rda(fish.hel)
>> fish.site<- scores(fish.pca,display="sites",scaling=3)
>> fish.spp<- scores(fish.pca,display="species",scaling=3)
>> fish.site[,"PC1"]<- -1*(fish.site[,"PC1"])
>> fish.spp[,"PC1"]<- -1*(fish.spp[,"PC1"])
>> graph<- plot(fish.pca,display=c("sites","species"),type="n",scaling=3) #
> how do I get the plot to draw up the blank display based on the reversed
> site and species scores?
>
> Any help appreciated.
>
> cheers
>
> Andy



More information about the R-help mailing list