Skip to main content

3.9) Putting it all together


Finally, to show how easy it can be to perform advanced statistical analyses in R: obtain a principal components analysis on the swiss data by typing:
swiss.PCA <- prcomp(swiss, scale.=TRUE)

Then, to demonstrate some graphics features:
par(mfrow=c(1,1), tck=0.01, ps=11, cex.lab=1.2, mgp=c(3,0.5,0));
biplot(swiss.PCA, expand=1.25, cex=c(0.8,1), arrow.len=0.06, xlim=c(-0.35,0.5), ylim=c(-0.3,0.35));
mtext("Principal components analysis of socioeconomic indicators in Switzerland, 1888", side=3, line=3, cex=1.2)

NB The ; at the end of each line are just to ensure the line breaks are observed. They aren’t essential if you enter the code line by line.