SHARE
TWEET

Untitled

a guest Jun 15th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rm(list=ls())
  2. library(LalRUtils)
  3. load_or_install(c('tidyverse', 'data.table', 'magrittr',
  4.   'factoextra'))
  5. nrow = 1e3
  6.  
  7. df <- data.frame(
  8.     x = rnorm(nrow),
  9.     y = runif(nrow),
  10.     z = runif(nrow)
  11.   )
  12.  
  13. pc <- prcomp(df, scale = F)
  14.  
  15. pc %>% str
  16. #%%
  17.  
  18. data(decathlon2)
  19. decathlon2.active <- decathlon2[1:23, 1:10]
  20. head(decathlon2.active[, 1:6])
  21.  
  22. res.pca <- prcomp(decathlon2.active, scale = TRUE)
  23.  
  24. res.pca
  25.  
  26. #%%
  27. fviz_pca_ind(res.pca,
  28.              col.ind = "cos2", # Color by the quality of representation
  29.              gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
  30.              repel = TRUE     # Avoid text overlapping
  31.              )
  32.  
  33. #%%
  34. fviz_pca_var(res.pca,
  35.              col.var = "contrib", # Color by contributions to the PC
  36.              gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
  37.              repel = TRUE     # Avoid text overlapping
  38.              )
  39. #%%
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top