R/pca.R

# Recipe for proyecting data on PC

library(ggplot2)
library(ggbiplot)

# log transform
log.ir <- log(iris[, 1:4])
ir.species <- iris[, 5]

# apply PCA - scale. = TRUE is highly
# advisable, but default is FALSE.
ir.pca <- prcomp(log.ir,
                 center = TRUE,
                 scale. = TRUE)


g <- ggbiplot(ir.pca, obs.scale = 1, var.scale = 1,
              groups = ir.species, ellipse = TRUE,
              circle = TRUE)

plot(g)
caramirezal/plotFun documentation built on May 9, 2019, 9:57 p.m.