Learn R Programming

PopComm (version 1.0.0)

pca_sample: Generate PCA of Ligand-Receptor Interaction Scores

Description

This function performs principal component analysis (PCA) on ligand-receptor (LR) interaction scores across samples, and generates a scatter plot of the first two principal components. Optionally, sample metadata can be used to color the points.

Usage

pca_sample(
  lr_scores,
  metadata,
  selected_sender = NULL,
  selected_receiver = NULL,
  color_by = NULL,
  n_components = 2
)

Value

A list containing:

  • plot - ggplot object of the PCA scatter plot

  • df - data frame used for the PCA results

Arguments

lr_scores

Data frame containing LR interaction scores per sample (data frame).

metadata

Data frame containing sample metadata (data frame).

selected_sender

Specific sender cell type to filter, default is None (use all) (character).

selected_receiver

Specific receiver cell type to filter, default is None (use all) (character).

color_by

metadata column name to color points in PCA plot (character).

n_components

Number of principal components to extract (numeric, default: 2).

Examples

Run this code
# PCA of LR Interaction Scores
data(lr_scores_eg)
data(metadata_eg)

res <- pca_sample(
  lr_scores = lr_scores_eg,
  metadata = metadata_eg,
  color_by = "IFN_type"
  )

print(res$plot)
head(res$df)

Run the code above in your browser using DataLab