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 with further modifications suggested by Jared Smith.
scatterHist(x,y=NULL,smooth=TRUE,ab=FALSE,correl=TRUE,density=TRUE,ellipse=TRUE,
digits=2,method,cex.cor=1, title="Scatter plot + histograms", xlab=NULL,ylab=NULL,
smoother=FALSE,nrpoints=0, xlab.hist=NULL,ylab.hist=NULL,grid=FALSE, xlim=NULL,
ylim=NULL, x.breaks=11,y.breaks=11, x.space=0, y.space=0 ,freq=TRUE, x.axes=TRUE,
y.axes=TRUE,...)
scatter.hist(x,y=NULL,smooth=TRUE,ab=FALSE, correl=TRUE, density=TRUE, ellipse=TRUE,
digits=2, method,cex.cor=1, title="Scatter plot + histograms",
xlab=NULL,ylab=NULL,smoother=FALSE, nrpoints=0, xlab.hist=NULL, ylab.hist=NULL,
grid=FALSE, xlim=NULL,ylim=NULL,x.breaks=11,y.breaks=11,
x.space=0,y.space=0,freq=TRUE,x.axes=TRUE,y.axes=TRUE,...)
The X vector, or the first column of a data.frame or matrix.
The Y vector, of if X is a data.frame or matrix, the second column of X
if TRUE, then add a loess smooth to the plot
if TRUE, then show the best fitting linear fit
TRUE: Show the correlation
TRUE: Show the estimated densities
TRUE: draw 1 and 2 sigma ellipses and smooth
How many digits to use if showing the correlation
Which method to use for correlation ("pearson","spearman","kendall") defaults to "pearson"
if TRUE, use smoothScatter instead of plot. Nice for large N.
If using smoothScatter, show nrpoints as dots. Defaults to 0
If TRUE, show a grid for the scatter plot.
Adjustment for the size of the correlation
Label for the x axis
Label for the y axis
Allow specification for limits of x axis, although this seems to just work for the scatter plots.
Allow specification for limits of y axis
Number of breaks to suggest to the x axis histogram.
Number of breaks to suggest to the y axis histogram.
space between bars
Space between y bars
Show frequency counts, otherwise show density counts
Show the x axis for the x histogram
Show the y axis for the y histogram
Not currently available
Label for y axis histogram. Not currently available.
An optional title
Other parameters for graphics
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. The grid option provides a background grid to the scatterplot. )
pairs.panels
for multiple plots, multi.hist
for multiple histograms.
# NOT RUN {
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],grid=TRUE)
# }
Run the code above in your browser using DataLab