ez (version 3.0-1)

ezCor: Function to plot a correlation matrix with scatterplots, linear fits, and univariate density plots

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
)

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_adjust
Adjusts the bandwidth of the univariate density estimator. See "adjust" parameter in density
density_height
Proportion of the facet height taken up by the density plots.
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 coloring of the "significant" correlation coefficients.

Value

  • A ggplot2 object.

See Also

ANT, ANT2, ezANOVA, ezBoot, ezBootPlot, ezCor, ezDesign, ezMixed, link{ezMixedRel}, ezPerm, ezPlot, ezPrecis, ezPredict, ezResample, ezStats, progress_time, progress_timeCI

Examples

Run this code
########
# 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
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

Run the code above in your browser using DataLab