cor.rect.plot | R Documentation |
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.
cor.rect.plot(x, y, corr = TRUE, xlab = deparse(substitute(x)),
ylab = deparse(substitute(y)), col = c("#ff000055", "#0000ff55"),
...)
x |
The |
y |
The |
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 |
ylab |
The label for the |
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 |
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.
This function returns an invisible NULL, it is run for its side effects.
Greg Snow, 538280@gmail.com
cor
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.