Visualizing multivariate data using a biplot

In order to find how data and variables are mapped in regard to the principal component, you can use biplot, which plots data and projections of original features on to the first two components. In this recipe, we will demonstrate how to use biplot to plot both variables and data on the same figure.

Getting ready

Ensure that you have completed the previous recipe by generating a principal component object and saving it in variable eco.pca.

How to do it…

Perform the following steps to create a biplot:

  1. Create a scatter plot using component 1 and component 2:
    > plot(eco.pca$x[,1], eco.pca$x[,2], xlim=c(-6,6), ylim = c(-4,3))
    > text(eco.pca$x[,1], eco.pca$x[,2], eco.freedom[,2], cex=0.7, pos=4, col="red")
    

Get R for Data Science Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.