R/Cumulative_variance_plot.R

Defines functions Cumulative_variance_plot

Documented in Cumulative_variance_plot

#' 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)
}
rforbiodatascience22/PanRISK_package documentation built on April 24, 2022, 12:15 a.m.