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:
- 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")
- In addition, if you would like to add features on the plot, you can create the biplot using a generated principal component object:
> rownames(eco.pca$x...