Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rm(list=ls())
- library(LalRUtils)
- load_or_install(c('tidyverse', 'data.table', 'magrittr',
- 'factoextra'))
- nrow = 1e3
- df <- data.frame(
- x = rnorm(nrow),
- y = runif(nrow),
- z = runif(nrow)
- )
- pc <- prcomp(df, scale = F)
- pc %>% str
- #%%
- data(decathlon2)
- decathlon2.active <- decathlon2[1:23, 1:10]
- head(decathlon2.active[, 1:6])
- res.pca <- prcomp(decathlon2.active, scale = TRUE)
- res.pca
- #%%
- fviz_pca_ind(res.pca,
- col.ind = "cos2", # Color by the quality of representation
- gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
- repel = TRUE # Avoid text overlapping
- )
- #%%
- fviz_pca_var(res.pca,
- col.var = "contrib", # Color by contributions to the PC
- gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
- repel = TRUE # Avoid text overlapping
- )
- #%%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement