| corPlot | R Documentation |
Function to to draw and visualise correlation matrices. The primary purpose is as a tool for exploratory data analysis. Hierarchical clustering is used to group similar variables.
corPlot(
mydata,
pollutants = NULL,
type = "default",
cluster = TRUE,
method = "pearson",
use = "pairwise.complete.obs",
annotate = c("cor", "signif", "stars", "none"),
dendrogram = FALSE,
triangle = c("both", "upper", "lower"),
diagonal = TRUE,
cols = "default",
r.thresh = 0.8,
text.col = c("black", "black"),
key.title = NULL,
key.position = "none",
strip.position = "top",
auto.text = TRUE,
plot = TRUE,
key = NULL,
...
)
mydata |
A data frame which should consist of some numeric columns. |
pollutants |
the names of data-series in |
type |
Character string(s) defining how data should be split/conditioned
before plotting.
Most |
cluster |
Should the data be ordered according to cluster analysis. If
|
method |
The correlation method to use. Can be |
use |
How to handle missing values in the |
annotate |
What to annotate each correlation tile with. One of:
|
dendrogram |
Should a dendrogram be plotted? When |
triangle |
Which 'triangles' of the correlation plot should be shown?
Can be |
diagonal |
Should the 'diagonal' of the correlation plot be shown? The
diagonal of a correlation matrix is axiomatically always |
cols |
Colours to use for plotting. Can be a pre-set palette (e.g.,
|
r.thresh |
Values of greater than |
text.col |
The colour of the text used to show the correlation values. The first value controls the colour of negative correlations and the second positive. |
key.title |
Used to set the title of the legend. The legend title is
passed to |
key.position |
Location where the legend is to be placed. Allowed
arguments include |
strip.position |
Location where the facet 'strips' are located when
using |
auto.text |
Either |
plot |
When |
key |
Deprecated; please use |
... |
Addition options are passed on to
|
The corPlot() function plots correlation matrices. The implementation
relies heavily on that shown in Sarkar (2007), with a few extensions.
Correlation matrices are a very effective way of understating relationships
between many variables. The corPlot() shows the correlation coded in three
ways: by shape (ellipses), colour and the numeric value. The ellipses can be
thought of as visual representations of scatter plot. With a perfect positive
correlation a line at 45 degrees positive slope is drawn. For zero
correlation the shape becomes a circle. See examples below.
With many different variables it can be difficult to see relationships
between variables, i.e., which variables tend to behave most like one
another. For this reason hierarchical clustering is applied to the
correlation matrices to group variables that are most similar to one another
(if cluster = TRUE).
If clustering is chosen it is also possible to add a dendrogram using the
option dendrogram = TRUE. Note that dendrogramscan only be plotted for
type = "default" i.e. when there is only a single panel. The dendrogram can
also be recovered from the plot object itself and plotted more clearly; see
examples below.
It is also possible to use the openair type option to condition the data in
many flexible ways, although this may become difficult to visualise with too
many panels.
an openair object
David Carslaw
Jack Davison
Adapted from the approach taken by Sarkar (2007)
# basic plot
corPlot(mydata)
## Not run:
# plot by season
corPlot(mydata, type = "season")
# recover dendrogram when cluster = TRUE and plot it
res <- corPlot(mydata, plot = FALSE)
plot(res$clust)
# a more interesting are hydrocarbon measurements
hc <- importAURN(site = "my1", year = 2005, hc = TRUE)
# now it is possible to see the hydrocarbons that behave most
# similarly to one another
corPlot(hc)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.