#' Cumulative variance
#' Takes the pca fitted to the data and shows the cumulative variance plot
#' @param pca_fit
#'
#' @return cumulative_variance_plot
#' @export
#' @importFrom stats prcomp
#' @examples
Cumulative_variance_plot <- function(pca_fit){
cumulative_variance_plot <- pca_fit %>%
tidy(matrix = "eigenvalues") %>%
ggplot(aes(PC, cumulative)) +
geom_col(fill = "#0072B2", alpha = 0.8) +
scale_x_continuous(breaks = 1:10) +
scale_y_continuous(
labels = scales::percent_format(),
expand = expansion(mult = c(0, 0.1))) +
labs( title = "The cumulative explained variance ",
subtitle = "Together the first three PCs explains more than 60% of the total data variance") +
theme_minimal(base_size = 10,
base_family = "Avenir")+
theme(legend.position = "none")+
theme_minimal_hgrid(12)
return(cumulative_variance_plot)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.