Learn R Programming

fifer (version 1.1)

spearman.plot: Spearman plot

Description

Plots the relationship between two variables using a Spearman Plot

Usage

spearman.plot(x, y = NULL, dcol = "blue", lhist = 20, num.dnorm = 5 *
  lhist, plot.cor = TRUE, ...)

Arguments

x
either a matrix with two columns or a vector (if y is not NULL)
y
a vector
dcol
the color of the lines drawn for the density plot
lhist
the number of breaks in the histogram
num.dnorm
the number of breaks in the density line
plot.cor
logical. Should the spearman correlation be outputted in the plot?
...
arguments passed to plot

Details

Often data are not normally distributed, requiring the use of a spearman correlation to determine their relationship. However, doing so makes it difficult to visualize the data since scatterplots of raw data present the data as if a pearson correlation were used. This function plots the ranks of the data, while plotting along the axes the distributions of the raw data.

Examples

Run this code
### generate skewed data
x = rnorm(1000)^2
y = .6*x + rnorm(1000, 0, sqrt(1-.6^2))

spearman.plot(cbind(x,y), col="red", lhist=50)
spearman.plot(x=iris$Sepal.Length, y=iris$Sepal.Width)

Run the code above in your browser using DataLab