[R] scatterplots: (equal axes and overlay)

Roland Rau roland.rproject at gmail.com
Thu Jun 14 16:11:35 CEST 2007


Hi Matthias,

please see below for some code example.

Matthias von Rad wrote:
> Hi,
> I am doing lots of scatterplots for my dissertation and to make the
> comparable, I would like to have equal x- amd - y axis. Can I specify
> their scale?
> Another question adresses overlay scatterplots. Having prae and post
> measures for each case, is it possible to have them in one graph with
> symbols or colors for prae and post.

### first we create some hypothetical data

pre.x <- runif(n=100, min=0, max=10)
pre.y <- 1.5+2*pre.x+rnorm(n=length(pre.x), mean=pre.x, sd=1)

post.x <- runif(n=100, min=0, max=10)
post.y <- 20-3*post.x+rnorm(n=length(post.x), mean=post.x, sd=1)


## let's construct a plot from scratch, using type="n" to have an
## empty plotting area
plot(x=1,y=1, type="n", xlim=c(0,10), ylim=c(0,20), axes=FALSE,
      xlab="My X-Labels", ylab="My Y-Labels")
axis(side=1, at=seq(from=0, to=10, by=2.5))
axis(side=2, at=seq(from=0, to=20, by=5))
points(x=pre.x, y=pre.y, col="green", pch=19)
points(x=post.x, y=post.y, col="red", pch=19)

### and this makes it easy to find out which 'pch'-number plots which
### symbol:
plot(x=0:25, y=0:25, pch=0:25)


I hope this helps.

Best,
Roland



More information about the R-help mailing list