[R] [newbie] scatterplot with marginal histograms (done) and axes labels

KarstenW K.Weinert at gmx.net
Fri Nov 7 15:24:19 CET 2008


Hello,

I am stuck when I want to add axes labels to my scatterplot with histograms.
I guess it must be something  with par(mar=) or so, but could someone give
me a hint?

Here is what I got so far:

# adapted from
http://www.stat.ucl.ac.be/ISdidactique/comment/fichiers/r/scatterhist.rs and
from ?layout
#
# see also: 
#     - http://biom1.univ-lyon1.fr/ADE-4/ade4-html/s.hist.html (a function
called s.hist in package ade4)
#     - http://www.statmethods.net/graphs/scatterplot.html (shows how to do
some nice scatterplots, 
#       e.g. with the function scatterplot in package car)

scatterhist=function(x,y, xlab="", ylab=""){
 #oldpar = par(no.readonly = TRUE) # save default, for resetting...
 zones=matrix(c(2,0,1,3),ncol=2,byrow=TRUE)
 layout(zones,widths=c(4/5,1/5),heights=c(1/5,4/5))
 xhist <- hist(x, plot=FALSE)
 yhist <- hist(y, plot=FALSE)
 top <- max(c(xhist$counts, yhist$counts))
 par(mar=c(3,3,1,1))
 plot(x,y, xlab=xlab, ylab=ylab)
 par(mar=c(0,3,1,1))
 barplot(xhist$counts, axes=FALSE, ylim=c(0, top), space=0)
 par(mar=c(3,0,1,1))
 barplot(yhist$counts, axes=FALSE, xlim=c(0, top), space=0, horiz=TRUE)
 #par(oldpar) # reset to default
}

Now if I do
> x=rnorm(50)
> y=rnorm(50)
> scatterhist(x,y,xlab="x", ylab="y")

there are no axes labels.....
I also wonder why R complains if I uncomment the first and last line in the
function ("invalid value
for parameter fig specified").

Any hint appreciated,
Karsten.
-- 
View this message in context: http://www.nabble.com/-newbie--scatterplot-with-marginal-histograms-%28done%29-and-axes-labels-tp20381450p20381450.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list