plot_PCAs: Plot samples on pairwise sets of PCA axes, optionally...

View source: R/plot_PCAs.R

plot_PCAsR Documentation

Plot samples on pairwise sets of PCA axes, optionally plotting variables by shape and/or color

Description

This function plots samples on all pairwise sets of specified PCA axes. Points can have their shape and/or color set by variables provided in a design object.

Usage

plot_PCAs(
  scores_design_pca,
  PCs = 1:3,
  pvars.labs = "PC#",
  color_by_var = NULL,
  color_by_var_levels = NULL,
  color_var_lab = NULL,
  my_cols = c("blue", "red"),
  na_col = "grey50",
  pch_by_var = NULL,
  pch_by_var_levels = NULL,
  pch_var_lab = NULL,
  my_pch = NULL,
  text_by_var = NULL,
  plot_text_and_pch = FALSE,
  text_by_var_size = 1,
  add_legend = TRUE,
  file_prefix = NULL,
  plotdims = c(9, 9),
  point_order = "random"
)

Arguments

scores_design_pca

a matrix or data frame containing the principal component scores and (optionally) any other sample annotation to be used in plotting. Typically generated by running prcomp, then using cbind or similar to append sample annotation.

PCs

a numeric vector of principal component axes to include in plotting. Defaults to 1:3, which will cause the function to plot PC1 vs. PC2, PC1 vs. PC3, and PC2 vs. PC3.

pvars.labs

(optional) character vector containing axis labels. Can be generated by running PCA with calc_PCAs. Defaults to "PC#", which yields axis labels such as "PC1", "PC2", etc. Set to NULL to suppress axis labels.

color_by_var

(optional) character string or integer identifying the column in scores_design_pca to color points by. If not provided, points are plotted in black.

color_by_var_levels

(optional) character vector defining the order of elements in the variable used for coloring points; this order is used for the plot legend and to match the order of colors (if provided). If not provided, levels of the variable are ordered by order of appearance in scores_design_pca.

color_var_lab

(optional) string to be used as the title for the color legend.

my_cols

(optional) vector of colors to use for plotting. If color_by_var is numeric, should have two elements, providing the start and end points for a continuous color scale (generated by scale_color_gradient). If color_by_var is not numeric, should be a vector with one color for each level of color_by_var; if the number of values supplied is less than the numer of levels in color_by_var, additional values are interpolated using colorRampPalette. By default, uses a range from blue to red.

na_col

color to use for NA values of color_by_var.

pch_by_var

(optional) character string or integer identifying the column in scores_design_pca to vary point shapes by. If not provided, points are plotted as dots.

pch_by_var_levels

(optional) character vector defining the order of elements in the variable used for point shapes; this order is used for the plot legend and to match the order of shapes (if provided). If not provided, levels of the variable are ordered by order of appearance in scores_design_pca.

pch_var_lab

(optional) string to be used as the title for the point shape legend.

my_pch

vector of shapes to use for plotting. Required if plotting points by shape; if not provided, all points will be plotted as dots. Must contain at least as many elements as the number of unique elements in pch_by_var.

text_by_var

(optional) character string or integer identifying the column in scores_design_pca to plot as text.

plot_text_and_pch

boolean, whether to plot both text labels and points. If FALSE, text labels are plotted and points are not.

text_by_var_size

numeric, the scaling factor for the text labels; passed as size to geom_text.

add_legend

boolean, whether to include legend(s) on the plot for points plotted by variables.

file_prefix

a character string. If provided, the function outputs a pdf of the plot, named "file_prefixother_stuff.pdf", where other_stuff includes the PCs being plotted and variables for shape or color plotting. If NULL, plots are output to the current plotting device. Defaults to NULL.

plotdims

a numeric vector, the size (in inches) of the plotting object. Applies only if file_prefix is not NULL.

point_order

character string, specifying how to order the points. Currently accepted values are "random", which randomizes the order of the points, and "input", which sends the points to ggplot as they are in the input data frame. Defaults to "random".


mjdufort/RNAseQC documentation built on July 7, 2023, 6:46 p.m.