Learn R Programming

DataExplorer (version 0.6.0)

plot_correlation: Create correlation heatmap for discrete features

Description

This function creates a correlation heatmap for all discrete categories.

Usage

plot_correlation(data, type = c("all", "discrete", "continuous"),
  maxcat = 20L, title = NULL, ggtheme = theme_gray(),
  theme_config = list(legend.position = "bottom", axis.text.x =
  element_text(angle = 90)), ...)

Arguments

data

input data

type

column type to be included in correlation calculation. "all" for all columns, "discrete" for discrete features, "continuous" for continuous features.

maxcat

maximum categories allowed for each discrete feature. The default is 20.

title

plot title

ggtheme

complete ggplot2 themes. The default is theme_gray.

theme_config

a list of configurations to be passed to theme.

other arguments to be passed to cor.

Details

For discrete features, the function first dummifies all categories, then calculates the correlation matrix (see cor) and plots it.

To change default font family and size, you may pass base_size and base_family to ggtheme options, e.g., ggtheme = theme_gray(base_size = 15, base_family = "serif")

theme_config argument expects all inputs to be wrapped in a list object, e.g., to change the text color: theme_config = list("text" = element_text(color = "blue"))

Examples

Run this code
# NOT RUN {
# Load diamonds dataset from ggplot2
data("diamonds", package = "ggplot2")

# Plot correlation heatmap
plot_correlation(diamonds)
plot_correlation(diamonds, maxcat = 5)
plot_correlation(diamonds, type = "c")
plot_correlation(diamonds, type = "d")
# }

Run the code above in your browser using DataLab