psych (version 1.1.11)

scatter.hist: Draw a scatter plot with associated X and Y histograms, densitie and correlation

Description

Draw a X Y scatter plot with associated X and Y histograms with estimated densities. Partly a demonstration of the use of layout. Also includes lowess smooth or linear model slope, as well as correlation. Adapted from addicted to R example 78

Usage

scatter.hist(x,y=NULL,smooth=TRUE,ab=FALSE,correl=TRUE,density=TRUE,ellipse=TRUE,digits=2, cex.cor=1,title="Scatter plot + histograms",xlab=NULL,ylab=NULL,...)

Arguments

x
The X vector, or the first column of a data.frame or matrix.
y
The Y vector, of if X is a data.frame or matrix, the second column of X
smooth
if TRUE, then loess smooth it
ab
if TRUE, then show the best fitting linear fit
correl
TRUE: Show the correlation
density
TRUE: Show the estimated densities
ellipse
TRUE: draw 1 and 2 sigma ellipses and smooth
digits
How many digits to use if showing the correlation
cex.cor
Adjustment for the size of the correlation
xlab
Label for the x axis
ylab
Label for the y axis
title
An optional title
...
Other parameters for graphics

Details

Just a straightforward application of layout and barplot, with some tricks taken from pairs.panels. The various options allow for correlation ellipses (1 and 2 sigma from the mean), lowess smooths, linear fits, density curves on the histograms, and the value of the correlation. ellipse = TRUE implies smooth = TRUE )

See Also

pairs.panels for multiple plots, multi.hist for multiple histograms.

Examples

Run this code
data(sat.act)
with(sat.act,scatter.hist(SATV,SATQ))
#or for something a bit more splashy
scatter.hist(sat.act[5:6],pch=(19+sat.act$gender),col=c("blue","red")[sat.act$gender])

Run the code above in your browser using DataCamp Workspace