# NOT RUN {
library(spinifex)
library(ggplot2)
dat <- scale_sd(penguins[, 1:4])
clas <- penguins$species
bas <- basis_pca(dat)
proj <- as.data.frame(dat %*% bas)
ggplot() +
geom_point(aes(PC1, PC2), proj) +
draw_basis(bas, proj, "left") +
coord_fixed()
## Aesthetics and basis on specific facet levels
proj <- cbind(proj, clas = penguins$species)
bas <- cbind(as.data.frame(bas), clas = levels(clas)[2])
ggplot() +
facet_wrap(vars(clas)) +
geom_point(aes(PC1, PC2, color = clas, shape = clas), proj) +
draw_basis(bas, proj, "left") +
theme_bw() +
coord_fixed()
## To repeat basis in all facet levels don't cbind a facet variable.
# }
Run the code above in your browser using DataLab