plotCorrmatrix: Calculates and plots correlation matrices for a set of...

plotCorrmatrixR Documentation

Calculates and plots correlation matrices for a set of responses

Description

Having calculated the correlations a heat map indicating the magnitude of the correlations is produced using ggplot. In this heat map, the darker the red in a cell then the closer the correlation is to -1, while the deeper the blue in the cell, then the closer the correlation is to 1. Matrix plots of all pairwise combinations of the variables can be produced that includes the values of the the correlation coefficients. If pairs.sets is set, a matrix plot, along with the values of the correlation coefficients, is produced for each of the pair.sets. That is, the argument pairs.sets can be used to restrict the pairs in a matrix plot to those combinations within each set.

Usage

plotCorrmatrix(data, responses, which.plots = c("heatmap","matrixplots"), 
               title = NULL, labels = NULL, labelSize = 4, pairs.sets = NULL, 
               show.sig = TRUE, axis.text.size = 20, ggplotFuncs = NULL, 
               printPlot = TRUE, ...)

Arguments

data

A data.frame containing the columns of variables to be correlated.

responses

A character giving the names of the columns in data containing the variables to be correlated.

which.plots

A character specifying the plots of the correlations to be produced. The possibilities are one or both of heatmap and matrixplots.

title

Title for the plots.

labels

A character specifying the labels to be used in the plots. If labels is NULL, responses is used for the labels.

labelSize

A numeric giving the size of the labels in the matrixplots.

pairs.sets

A list each of whose components is a numeric giving the position of the variable names in responses that are to be included in the set. All pairs of variables in this pairs.set will be included in matrixplots.

show.sig

A logical indicating whetherto give asterisks on the heatmap and matrixplots that indicate that the correlations are significantly different from zero.

axis.text.size

A numeric giving the size of the labels on the axes of the heatmap.

ggplotFuncs

A list, each element of which contains the results of evaluating a ggplot function. It is created by calling the list function with a ggplot function call for each element. These functions are applied in creating the ggplot object.

printPlot

A logical indicating whether or not to print the plots.

...

allows passing of arguments to other functions; not used at present.

Details

The correlations and their p-values are producced using rcorr from the Hmisc package. The heatmap is produced using ggplot and the matrixplots are produced using GGally.

Value

A list object that has components heatmap and matrixplots. The component heatmap will contain the heatmap plot, if produced, as an object of class "ggplot", which can be plotted using print; otherwise NULL is returned. Similarly, if not NULL, the component matrixplots will contain a list with one or more components, depending on the setting of pair.sets, each of which is a scatterplot matrix stored as an object of class "ggmatrix".

Author(s)

Chris Brien

See Also

rcorr, GGally, ggplot.

Examples


data(exampleData)
longi.dat <- prepImageData(data=raw.dat, smarthouse.lev=1)
longi.dat <- within(longi.dat, 
                    {
                      Max.Height <- pmax(Max.Dist.Above.Horizon.Line.SV1,  
                                         Max.Dist.Above.Horizon.Line.SV2)
                      Density <- PSA/Max.Height
                      PSA.SV = (PSA.SV1 + PSA.SV2) / 2
                      Image.Biomass = PSA.SV * (PSA.TV^0.5)
                      Centre.Mass <- (Center.Of.Mass.Y.SV1 + Center.Of.Mass.Y.SV2) / 2
                      Compactness.SV = (Compactness.SV1 + Compactness.SV2) / 2
                    })
responses <- c("PSA","PSA.SV","PSA.TV", "Image.Biomass", "Max.Height","Centre.Mass",
               "Density", "Compactness.TV", "Compactness.SV")
plotCorrmatrix(longi.dat, responses, pairs.sets=list(c(1:4),c(5:7)))


briencj/growthPheno documentation built on April 14, 2025, 6:17 p.m.