correct: Plot a visualization of the correlation using colored...

Description Usage Arguments Details Value Author(s) See Also Examples

Description

This function creates a scatterplot of the data, then adds colored rectangles between the points and the mean of x and y to represent the idea of the correlation coefficient.

Usage

1
2
3
cor.rect.plot(x, y, corr = TRUE, xlab = deparse(substitute(x)),
  ylab = deparse(substitute(y)), col = c("#ff000055", "#0000ff55"),
  ...)

Arguments

x

The x value or any object that can be interpreted by xy.coords

y

The y value

corr

Should the standardized axes (right and top) show the values divided by the standard deviation (TRUE, which shows correlation ideas) or not (FALSE, shows covariance idea)

xlab

The label for the x axis

ylab

The label for the y axis

col

A vector of length 2 with the colors to use for the fill of the rectangles, the 1st value will be used for "positive" rectangles and the 2nd value will be used for the "negative" rectangles.

...

Possible further arguments, currently ignored

Details

This will create a scatterplot of the data, draw refrence lines at the mean of x and the mean of y, then draw rectangles from the mean point to the data points. The right and top axes will show the centered (and possibly scaled if corr=TRUE) values.

The idea is that the correlation/covariance is based on summing the area of the "positive" rectangles and subtracting the sum of the areas of the "negative" rectangles (then dividing by n-1). If the positive and negative areas are about the same then the correlation/covariance is near 0, if there is more area in the positive rectangles then the correlation/covariance will be positive.

Value

This function returns an invisible NULL, it is run for its side effects.

Author(s)

Greg Snow, 538280@gmail.com

See Also

cor

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## low correlation
x <- rnorm(25)
y <- rnorm(25)
cor(x,y)
cor.rect.plot(x,y)

## Positive correlation
x <- rnorm(25)
y <- x + rnorm(25,3, .5)
cor(x,y)
cor.rect.plot(x,y)

## negative correlation
x <- rnorm(25)
y <- rnorm(25,10,1.5) - x
cor(x,y)
cor.rect.plot(x,y)

## zero correlation but a definite relationship
x <- -5:5
y <- x^2
cor(x,y)
cor.rect.plot(x,y)

Example output

[1] -0.1661177
[1] 0.8934137
[1] -0.6006216
[1] 0

TeachingDemos documentation built on April 2, 2020, 3:01 a.m.