plotCorr: Static heatmaps of correlation matrices

Description Usage Arguments Details Value See Also Examples

View source: R/coin_multivariate.R

Description

Generates heatmaps of correlation matrices using ggplot2. This enables correlating any set of indicators against any other, and supports calling named aggregation groups of indicators. The withparent argument generates tables of correlations only with parents of each indicator. Also supports discrete colour maps using flagcolours, different types of correlation, and groups plots by higher aggregation levels.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
plotCorr(
  COIN,
  dset = "Raw",
  icodes = NULL,
  aglevs = 1,
  cortype = "pearson",
  withparent = "parent",
  grouplev = NULL,
  box_level = NULL,
  showvals = TRUE,
  flagcolours = FALSE,
  flagthresh = c(-0.4, 0.3, 0.9),
  pval = 0.05,
  insig_colour = "#F0F0F0",
  text_colour = NULL,
  discrete_colours = NULL,
  box_colour = NULL,
  out2 = "fig"
)

Arguments

COIN

The COIN object

dset

The target data set.

icodes

An optional list of character vectors where the first entry specifies the indicator/aggregate codes to correlate against the second entry (also a specification of indicator/aggregate codes)

aglevs

The aggregation levels to take the two groups of indicators from. See getIn() for details.

cortype

The type of correlation to calculate, either "pearson", "spearman", or "kendall" (see stats::cor()).

withparent

If aglev[1] != aglev[2], and equal "parent" will only plot correlations of each row with its parent (default). If "family", plots the lowest aggregation level in aglevs against all its parent levels. If "none" plots the full correlation matrix.

grouplev

The aggregation level to group correlations by if aglev[1] == aglev[2]. By default, groups correlations into the aggregation level above. Set to 0 to disable grouping and plot the full matrix.

box_level

The aggregation level to draw boxes around if aglev[1] == aglev[2].

showvals

If TRUE, shows correlation values. If FALSE, no values shown.

flagcolours

If TRUE, uses discrete colour map with thresholds defined by flagthresh. If FALSE uses continuous colour map.

flagthresh

A 3-length vector of thresholds for highlighting correlations, if flagcolours = TRUE. flagthresh[1] is the negative threshold. Below this value, values will be flagged red. flagthresh[2] is the "weak" threshold. Values between flagthresh[1] and flagthresh[2] are coloured grey. flagthresh[3] is the "high" threshold. Anything between flagthresh[2] and flagthresh[3] is flagged "OK", and anything above flagthresh[3] is flagged "high".

pval

The significance level for plotting correlations. Correlations with p < pval will be shown, otherwise they will be plotted as the colour specified by insig_colour. Set to 0 to disable this.

insig_colour

The colour to plot insignificant correlations. Defaults to a light grey.

text_colour

The colour of the correlation value text (default white).

discrete_colours

An optional 4-length character vector of colour codes or names to define the discrete colour map if flagcolours = TRUE (from high to low correlation categories). Defaults to a green/blue/grey/purple.

box_colour

The line colour of grouping boxes, default black.

out2

If "fig" returns a plot, if "dflong" returns the correlation matrix in long form, if "dfwide", returns the correlation matrix in wide form. The last option here is probably useful if you want to present a table of the data in a report.

Details

This function calls getCorr().

Note that this function can only call correlations within the same data set (i.e. only one data set in .$Data).

Value

If out2 = "fig" returns a plot generated with ggplot2. These can be edited further with ggplot2 commands. If out2 = "dflong" returns the correlation matrix as a data frame in long form, if out2 = "dfwide", returns the correlation matrix in wide form. The last option here is probably useful if you want to present a table of the data in a report.

See Also

Examples

1
2
3
4
5
6
# build ASEM COIN
ASEM <- assemble(IndData = ASEMIndData, IndMeta = ASEMIndMeta, AggMeta = ASEMAggMeta)
# correlation data frame of indicators in connectivity sub-index, grouped by pillar
corrs <- plotCorr(ASEM, dset = "Raw", icodes = "Conn", aglevs = 1,
showvals = F, out2 = "dflong")
# NOTE to create a plot instead set out2 = "fig"

COINr documentation built on Nov. 30, 2021, 9:06 a.m.