Skip to content

Instantly share code, notes, and snippets.

@monogenea
Created October 7, 2019 18:14
Show Gist options
  • Save monogenea/4c41d67981d947b4097894172c29baf8 to your computer and use it in GitHub Desktop.
Save monogenea/4c41d67981d947b4097894172c29baf8 to your computer and use it in GitHub Desktop.
# simple PCA, plot
pcaRec <- myRec %>%
step_pca(all_predictors())
myPCA <- prep(pcaRec, training = trainSet, retain = T) %>%
juice()
colGrad <- trainSet$Y/100 # add color
plot(myPCA$PC1, myPCA$PC2,
col = rgb(1 - colGrad, 0, colGrad,.5),
pch = 16, xlab = "PC1", ylab = "PC2")
legend("topleft", pch = 16,
col = rgb(c(0,.5,1), 0, c(1,.5,0), alpha = .5),
legend = c("Pleasant", "Neutral", "Unpleasant"), bty = "n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment