Learn R Programming

daltoolbox (version 1.3.717)

plot_correlation: Plot correlation

Description

Correlation heatmap with optional labels and triangle filtering.

Usage

plot_correlation(
  df,
  vars = NULL,
  method = c("pearson", "spearman", "kendall"),
  use = "pairwise.complete.obs",
  triangle = c("full", "upper", "lower"),
  reorder = c("none", "hclust", "alphabetical"),
  digits = 2,
  label_size = 3,
  tile_color = "white",
  show_diag = TRUE,
  title = NULL
)

Value

returns a ggplot2::ggplot graphic

Arguments

df

data.frame with numeric columns

vars

optional vector of column names to include

method

correlation method: "pearson", "spearman", or "kendall"

use

handling of missing values for stats::cor

triangle

which triangle to show: "full", "upper", or "lower"

reorder

reordering strategy: "none", "hclust", or "alphabetical"

digits

number of digits for labels

label_size

size of label text

tile_color

border color for tiles

show_diag

whether to show the diagonal

title

optional plot title

Details

Computes a correlation matrix from numeric columns (or vars) and renders a ggplot2 heatmap with values annotated. Supports reordering by hierarchical clustering or alphabetically.

Examples

Run this code
data(iris)
grf <- plot_correlation(iris[,1:4])
plot(grf)

Run the code above in your browser using DataLab