barmap_commun: Barmap of communalities

View source: R/user_functions.R

barmap_communR Documentation

Barmap of communalities

Description

Plot a Barmap of the communalities from a PCA solution given the first ndim PCs.

Usage

barmap_commun(
  pca,
  pca_data,
  ndim = 1:5,
  load_list = NULL,
  conf = 0.95,
  plot_original = TRUE,
  plot_list_center = F,
  plot_legend = TRUE,
  text_values = F,
  text_size = 2,
  var_order = "increasing",
  vars = NULL,
  colors = c("white", "firebrick1"),
  gradient_color = TRUE
)

Arguments

pca

Object of class prcomp, princals, or data.frame. If object is a prcomp or princals object, pca_data is required, and the loadings will be extracted. If object is a data.frame object, the dataframe needs to be formatted as: first column named Variables and all other columns corresponding to a PC. One row per variable. The values are the loadings.

pca_data

Data passed to the prcomp or princals function.

ndim

Numeric. Number of PCs to plot

load_list

List. List of loading matrices used to plot percentile confidence intervals around the average. If NULL, no error bars are plotted. Default=NULL

conf

Numeric. Confidence level used when load_list is provided.

plot_original

Logical. Whether to plot the communalities obtained from the values passed to pca and pca_data.

plot_list_center

Logical. Whether to plot the average communalities obtained from load_list.

plot_legend

Logical. Whether legend should be plotted.

text_values

Logical. Whether to plot the values of the communalities or not. Default=FALSE

text_size

Numeric. Size of the text_values.

var_order

Character. Specify the order of the variables in the plot by the communality values, starting at 12 o’clock and moving counterclockwise. Possible values: 'abs decreasing': plot by decreasing absolute value; 'abs increasing': plot by increasing absolute value; 'decreasing'; or 'increasing’.

vars

Character vector. Variables will be ordered as the provided variable names. Non-specified variables will be excluded from the plot. By default variables are ordered in alphabetically by ggplot.

colors

Character vector of length 2. Vector with the character name or hexadecimal number (e.g. "#FF0000") of two colors, the lower color and the higher color for the gradient used in the plot. Hexadecimal number can be obtained using rgb for example.

gradient_color

Logical. Whether colors should be plotted as a gradient proportional to the communalities.

Value

Returns a ggplot2 object.

Author(s)

Abel Torres Espin

Examples

data(mtcars)
pca_mtcars<-prcomp(mtcars, center = TRUE, scale. = TRUE)

barmap_commun(pca = pca_mtcars, pca_data = mtcars, ndim = 1:4)


ucsf-ferguson-lab/syndRomics documentation built on June 26, 2022, 5:36 p.m.