layer_stat_cor_plot: Visualize the correlation of layer modeling t-statistics with...

View source: R/layer_stat_cor_plot.R

layer_stat_cor_plotR Documentation

Visualize the correlation of layer modeling t-statistics with ComplexHeatmap

Description

This function makes a ComplexHeatmap from the correlation matrix between a reference and query modeling statistics from layer_stat_cor(). For example, between the query statistics from a set of cell cluster/types derived from scRNA-seq or snRNA-seq data (among other types) and the reference layer statistics from the Human DLPFC Visium data (when using the default arguments).

Usage

layer_stat_cor_plot(
  cor_stats_layer,
  color_max = max(cor_stats_layer),
  color_min = min(cor_stats_layer),
  color_scale = c("#762A83", "#F7F7F7", "#1B7837"),
  query_colors = NULL,
  reference_colors = NULL,
  annotation = NULL,
  ...
)

Arguments

cor_stats_layer

The output of layer_stat_cor().

color_max

A numeric(1) specifying the highest correlation value for the color scale (should be between 0 and 1).

color_min

A numeric(1) specifying the lowest correlation value for the color scale (should be between 0 and -1).

color_scale

A character(3) vector specifying the color scale for the fill of the heatmap. The first value is used for color_min, the second one for zero, and the third for color_max.

query_colors

named character vector of colors, Adds colors to query row annotations.

reference_colors

named character vector of colors, Adds colors to reference column annotations.

annotation

annotation data.frame output of annotate_registered_clusters(), adds 'X' for good confidence annotations, '*' for poor confidence.

...

Additional parameters passed to ComplexHeatmap::Heatmap() such as cluster_rows and cluster_columns.

Details

Includes functionality to add color annotations, (helpful to match to colors in Visium spot plots), and annotations from annotate_registered_clusters().

Value

(Heatmap-class) plot of t-stat correlations

Author(s)

Louise Huuki-Myers

See Also

Other Layer correlation functions: annotate_registered_clusters(), layer_stat_cor()

Examples

## Obtain the necessary data
## reference human pilot modeling results
if (!exists("modeling_results")) {
    modeling_results <- fetch_data(type = "modeling_results")
}

## query spatialDLPFC modeling results
query_modeling_results <- fetch_data(
    type = "spatialDLPFC_Visium_modeling_results"
)

## Compute the correlations
cor_stats_layer <- layer_stat_cor(
    stats = query_modeling_results$enrichment,
    modeling_results,
    model_type = "enrichment"
)

## Visualize the correlation matrix

## Default plot with no annotations and defaults for ComplexHeatmap()
layer_stat_cor_plot(cor_stats_layer)

## add colors
## add libd_layer_colors to reference Human Pilot layers
layer_stat_cor_plot(cor_stats_layer, reference_colors = libd_layer_colors)

## obtain colors for the query clusters
cluster_colors <- get_colors(clusters = rownames(cor_stats_layer))
layer_stat_cor_plot(cor_stats_layer,
    query_colors = cluster_colors,
    reference_colors = libd_layer_colors
)

## Apply additional ComplexHeatmap param
layer_stat_cor_plot(cor_stats_layer,
    cluster_rows = FALSE,
    cluster_columns = FALSE
)

## Add annotation
annotation_df <- annotate_registered_clusters(
    cor_stats_layer,
    confidence_threshold = .55
)
layer_stat_cor_plot(cor_stats_layer, annotation = annotation_df)

## All together
layer_stat_cor_plot(
    cor_stats_layer,
    query_colors = cluster_colors,
    reference_colors = libd_layer_colors,
    annotation = annotation_df,
    cluster_rows = FALSE,
    cluster_columns = FALSE
)


LieberInstitute/spatialLIBD documentation built on Dec. 19, 2024, 7:12 p.m.