Description Usage Arguments Details Source See Also Examples
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.
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, ...)
|
x |
A complete correlation matrix |
psychOptions |
a named list(!) of options to be passed to the psych package.
Do not include the |
factanalOptions |
a named list(!) of options to be passed to the factanal
function in base R. |
ordering |
Order cols/rows based on |
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
|
cexCol |
positive numbers. If not missing, it will override
|
digits |
integer indicating the number of decimal places to be used by round for 'label'. |
cellnote |
(optional) matrix of the same dimensions as |
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
|
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. |
show_grid |
|
anim_duration |
Number of milliseconds to animate zooming in and out.
For large |
... |
currently ignored |
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.
Base code comes from d3heatmap package's core function, which was mostly gutted, and all dendrogram functionality replaced with a factor analytic approach.
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')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.