Learn R Programming

pubrplot (version 0.0.1)

plot_cor: Correlation Heatmap Plot

Description

Creates a publication-ready correlation heatmap for numeric variables in a data frame. Each tile shows the correlation coefficient, with optional significance stars.

Usage

plot_cor(
  data,
  method = "pearson",
  conf.level = 0.95,
  stars = TRUE,
  plot.title = NULL,
  var.labels = NULL
)

Value

A ggplot object showing the correlation heatmap with correlation coefficients and significance stars.

Arguments

data

A data frame containing numeric variables to correlate.

method

Correlation method: "pearson", "spearman", or "kendall". Default is "pearson".

conf.level

Confidence level for correlation confidence intervals. Default is 0.95.

stars

Logical. If TRUE, adds significance stars based on p-values. Default is TRUE.

plot.title

Character string specifying the plot title. If NULL, a default title is used.

var.labels

Optional character vector of variable labels to replace column names in the plot. Must match number of numeric columns.

Examples

Run this code
plot_cor(mtcars)
plot_cor(mtcars, var.labels = colnames(mtcars))
plot_cor(mtcars, method = "spearman", stars = FALSE)

Run the code above in your browser using DataLab