Skip to content

reflecting a PCA biplot

3 messages · Andrew Halford, Allan Engelhardt (CYBAEA), Gavin Simpson

#
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:
#
On Tue, 2011-08-09 at 22:57 +1000, Andrew Halford wrote:
Do you mean something like...?

require(vegan)
data(dune)
mod <- rda(dune)
si.scrs <- scores(mod, display = "sites", scaling = 3, choices = 1:2)
sp.scrs <- scores(mod, display = "species", scaling = 3, choices = 1:2)

si.scrs[, "PC1"] <- -1 * si.scrs[, "PC1"]
sp.scrs[, "PC1"] <- -1 * sp.scrs[, "PC1"]

xlim <- range(0, si.scrs[, 1], sp.scrs[, 1])
ylim <- range(0, si.scrs[, 2], sp.scrs[, 2])

plot(si.scrs[,1], si.scrs[,2], ylim = ylim, xlim = xlim,
     ylab = "PC2", xlab = "PC1", cex = 0.7, asp = 1)
abline(h = 0, lty = "dotted")
abline(v = 0, lty = "dotted")
points(sp.scrs[,1], sp.scrs[,2], col = "red", pch = 3, cex = 0.7)
box()

For non-standard plotting of ordination objects, our advice has always
been to build the plot up from lower-level plotting functions rather
than the specific methods supplied with vegan.

A comparison: (not quite the same, I know, but close enough)

layout(matrix(1:2, ncol = 2))
plot(mod, display=c("sites","species"), type = "p", scaling=3,
     main = "Original")
plot(si.scrs[,1], si.scrs[,2], ylim = ylim, xlim = xlim,
     ylab = "PC2", xlab = "PC1", cex = 0.7, asp = 1,
     main = "Flipped PC1")
abline(h = 0, lty = "dotted")
abline(v = 0, lty = "dotted")
points(sp.scrs[,1], sp.scrs[,2], col = "red", pch = 3, cex = 0.7)
box()
layout(1)

If you want type = "t", the default for plot.cca, then use the same
coordinates but extract the relevant labels from the two scores objects:

plot(si.scrs[,1], si.scrs[,2], ylim = ylim, xlim = xlim,
     ylab = "PC2", xlab = "PC1", cex = 0.7, asp = 1,
     type = "n") ## no plotting this time first
abline(h = 0, lty = "dotted")
abline(v = 0, lty = "dotted")
text(si.scrs[,1], si.scrs[,2], labels = rownames(si.scrs),
     cex = 0.7) ## add site and species scores as labels
text(sp.scrs[,1], sp.scrs[,2], labels = rownames(sp.scrs),
     col = "red", cex = 0.7)
box()

HTH

G