ezCor {ez}R Documentation

Compute and plot an information-dense correlation matrix

Description

This function provides simultaneous visualization of a correlation matrix, scatter-plot with linear fits, and univariate density plots for multiple variables.

Usage

ezCor(
    data
    , r_size_lims = c(10,30)
    , point_alpha = .5
    , density_height = 1
    , density_adjust = 1
    , density_colour = 'white'
    , label_size = 10
    , label_colour = 'black'
    , label_alpha = .5
    , lm_colour = 'red'
    , ci_colour = 'green'
    , ci_alpha = .5
    , test_alpha = .05
    , test_correction = 'none'
)

Arguments

data

Data frame containing named columns of data only.

r_size_lims

Minimum and maximum size of the text reporting the correlation coefficients. Minimum is mapped to coefficients of 0 and maximum is mapped to coefficients of 1, with the mapping proportional to r^2.

point_alpha

Transparency of the data points (1 = opaque).

density_height

Proportion of the facet height taken up by the density plots.

density_adjust

Adjusts the bandwidth of the univariate density estimator. See adjust parameter in density.

density_colour

Colour of the density plot.

label_size

Size of the variable labels on the diagonal.

label_colour

Colour of the variable labels on the diagonal.

label_alpha

Transparency of the variable labels on the diagonal (1 = opaque).

lm_colour

Colour of the fitted line.

ci_colour

Colour of the confidence interval surrounding the fitted line.

ci_alpha

Transparency of the confidence interval surrounding the fitted line (1 = opaque).

test_alpha

Type-I error rate requested for colouring of the “significant” correlation coefficients.

test_correction

Character string specifying the type of correction for multiple comparisons applied to the value specified by test_alpha. Possible values are “none”, “bonferroni”, and “sidak”,

Value

A printable/modifiable ggplot2 object.

Author(s)

Michael A. Lawrence mike.lwrnc@gmail.com
Visit the ez development site at http://github.com/mike-lawrence/ez
for the bug/issue tracker and the link to the mailing list.

Examples

########
# Set up some fake data
########
library(MASS)
N=100

#first pair of variables
variance1=1
variance2=2
mean1=10
mean2=20
rho = .8
Sigma=matrix(
    c(
        variance1
        , sqrt(variance1*variance2)*rho
        , sqrt(variance1*variance2)*rho
        , variance2
    )
    , 2
    , 2
)
pair1=mvrnorm(N,c(mean1,mean2),Sigma,empirical=TRUE)

#second pair of variables
variance1=10
variance2=20
mean1=100
mean2=200
rho = -.4
Sigma=matrix(
    c(
        variance1
        , sqrt(variance1*variance2)*rho
        , sqrt(variance1*variance2)*rho
        , variance2
    )
    , 2
    , 2
)
pair2=mvrnorm(N,c(mean1,mean2),Sigma,empirical=TRUE)

my_data=data.frame(cbind(pair1,pair2))

########
# Now plot
########
p = ezCor(
    data = my_data
)
print(p)

#you can modify the default colours of the
##correlation coefficients as follows
library(ggplot2)
p = p + scale_colour_manual(values = c('red','blue'))
print(p)
#see the following for alternatives:
# http://had.co.nz/ggplot2/scale_manual.html
# http://had.co.nz/ggplot2/scale_hue.html
# http://had.co.nz/ggplot2/scale_brewer.html


[Package ez version 4.4-0 Index]