Alex Rivera | Logout

Plotting pca biplot with ggplot2

Asked 2011-07-05T05:44:28.593
43

I wonder if it is possible to plot pca biplot results with ggplot2. Suppose if I want to display the following biplot results with ggplot2

fit <- princomp(USArrests, cor=TRUE)
summary(fit)
biplot(fit)

Any help will be highly appreciated. Thanks

Edit
Report

1 Answer

4

This will get the states plotted, though not the variables

fit.df <- as.data.frame(fit$scores)
fit.df$state <- rownames(fit.df)

library(ggplot2)
ggplot(data=fit.df,aes(x=Comp.1,y=Comp.2))+
  geom_text(aes(label=state,size=1,hjust=0,vjust=0))

enter image description here

answered 2011-07-05T06:57:12.513

Your Answer