# NOT RUN {
mat <- as.matrix(iris[, 1:4])
s <- svd(mat)
tidy_u <- tidy(s, matrix = "u")
head(tidy_u)
tidy_d <- tidy(s, matrix = "d")
tidy_d
tidy_v <- tidy(s, matrix = "v")
head(tidy_v)
library(ggplot2)
library(dplyr)
ggplot(tidy_d, aes(PC, percent)) +
geom_point() +
ylab("% of variance explained")
tidy_u %>%
mutate(Species = iris$Species[row]) %>%
ggplot(aes(Species, loading)) +
geom_boxplot() +
facet_wrap(~ PC, scale = "free_y")
# }
Run the code above in your browser using DataLab