corrheat: D3 Heatmap widget for correlation matrices

Description Usage Arguments Details Source See Also Examples

View source: R/corrheat.R

Description

Creates a D3.js-based heatmap widget specifically geared toward correlation matrices. All dendrogram related functionality related to the original d3heatmap function is removed, and replaced with an ordering based on a factor analysis.

Usage

1
2
3
4
5
6
7
corrheat(x, psychOptions = NULL, factanalOptions = NULL,
  ordering = c("fa", "raw", "first", "absolute"), labRow = rownames(x),
  labCol = colnames(x), cexRow, cexCol, digits = 3L, cellnote,
  cellnote_scale = FALSE, theme = NULL, width = NULL, height = NULL,
  xaxis_height = 80, yaxis_width = 120, xaxis_font_size = NULL,
  yaxis_font_size = NULL, brush_color = "#0000FF", show_grid = TRUE,
  anim_duration = 500, ...)

Arguments

x

A complete correlation matrix

psychOptions

a named list(!) of options to be passed to the psych package. Do not include the nfactors argument, as that is chosen automatically. Default is NULL.

factanalOptions

a named list(!) of options to be passed to the factanal function in base R. psychOptions will be checked first, and if present the psych package will be used and override this argument. Do not include the factors argument, as that is chosen automatically. Default is NULL.

ordering

Order cols/rows based on psych::fa.sort (default), max raw ("raw"), or absolute ("absolute") loadings across all factors, or based on the first factor's raw loadings from psych::fa or factanal.

labRow

character vectors with row labels to use (from top to bottom); default to rownames(x).

labCol

character vectors with column labels to use (from left to right); default to colnames(x).

cexRow

positive numbers. If not missing, it will override xaxis_font_size and will give it a value cexRow*14

cexCol

positive numbers. If not missing, it will override yaxis_font_size and will give it a value cexCol*14

digits

integer indicating the number of decimal places to be used by round for 'label'.

cellnote

(optional) matrix of the same dimensions as x that has the human-readable version of each value, for displaying to the user on hover. If NULL, then x will be coerced using as.character. If missing, it will use x, after rounding it based on the digits parameter.

cellnote_scale

logical (default is FALSE). IF cellnote is missing and x is used, should cellnote be scaled if x is also scaled?

theme

A custom CSS theme to use. Currently the only valid values are "" and "dark". "dark" is primarily intended for standalone visualizations, not R Markdown or Shiny.

width

Width in pixels (optional, defaults to automatic sizing).

height

Height in pixels (optional, defaults to automatic sizing).

xaxis_height

Size of axes, in pixels.

yaxis_width

Size of axes, in pixels.

xaxis_font_size

Font size of axis labels, as a CSS size (e.g. "14px" or "12pt").

yaxis_font_size

Font size of axis labels, as a CSS size (e.g. "14px" or "12pt").

brush_color

The base color to be used for the brush. The brush will be filled with a low-opacity version of this color. "#RRGGBB" format expected.

show_grid

TRUE to show gridlines, FALSE to hide them, or a numeric value to specify the gridline thickness in pixels (can be a non-integer).

anim_duration

Number of milliseconds to animate zooming in and out. For large x it may help performance to set this value to 0.

...

currently ignored

Details

d3heatmap was a great tool for matrix visualization, though it has largely been abandoned in favor of heatmaply, which I recommended for standard matrices, though it also has functionality for correlation matrices.

Correlation matrices are typically better visualized rather than parsed numerically, and while one can do so with various packages at this point, they invariably only order based on cluster analysis (for reasons unknown), and one often may not want the cluster based approach to ordering if dealing with a correlation matrix, which may be too small column-wise to be useful for a cluster analysis, or may be a specific type of data more amenable to a measurement error approach (e.g. items from a particular scale).

corrheat produces a color coded matrix in which Blue represents positive, and Red, negative correlations, and fades to white the smaller the values are. The ordering is based on the results of a factor analysis from the fa package (which is required). Though one can use factanal from base R, it's not recommended, and can actually be reproduced with an additional argument to the psych options (as such I will likely deprecate this option). This function does not currently allow choice of the number of factors. Instead, the number of factors is chosen to more likely 'just work' for visualization purposes (nfact = 1 if ncol <=4, else floor(sqrt(ncol(x)))), which is all we are worried about here. If you want explore a factor analysis you should do that separately.

Source

Base code comes from d3heatmap package's core function, which was mostly gutted, and all dendrogram functionality replaced with a factor analytic approach.

See Also

fa, factanal

Examples

1
2
3
4
5
library(heatR)
corrheat(cor(mtcars), factanalOptions=list(rotation='varimax'), ordering='absolute')
corrheat(cor(mtcars), factanalOptions=list(rotation='varimax'), ordering='raw')
corrheat(Harman74.cor$cov, psychOptions=list(fm='ml'))
corrheat(cor(state.x77), psychOptions=list(fm='ml'), ordering='raw')

m-clark/heatR documentation built on May 21, 2019, 9:17 a.m.