Make biplot using ggplot.

Principal Component Analysis (PCA) is a statistical procedure that uses an orthogonal transformation to convert a set of observations of possibly correlated variables into set of values of linearly un correlated variables. (from wiki)
R can preform PCA very simple command “prcomp”.
The result can visualise using biplot function.
ggplot2 is a plotting system for R, it can make very rich graphs using simple command.
I want to draw biplot using ggplot2, and found good package “ggbiplot”.
If you interested in that, you can install following command :-).
From R command prompt.

install.packages("devtools")  # also need install ggplot2
install_github("ggbiplot", "vqv")

OK, let’s draw biplot

> library("ggbiplot")
> data(wine)
> wine.pca <- prcomp(wine,scale.=TRUE)
> g<-ggbiplot(wine.pca, obs.scale=1, var.scale=1, groups=wine.class, ellipse=TRUE, circle=TRUE)
> g<-g+scale_color_discrete(name="")
> g<-opts(legend.discription="horiz",legend.posion="top")
Error: 'opts' is deprecated. Use 'theme' instead. (Defunct; last used in version 0.9.1) # opps! I got error
> print(g)

I got biplot.

Good job!


One thought on “Make biplot using ggplot.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s