[R] x axis problems

Duncan Murdoch murdoch at stats.uwo.ca
Mon May 14 14:42:45 CEST 2007


On 5/14/2007 7:45 AM, Ener Borg wrote:
> I have been searching for the R manual, unable to solve my problem.
> 
> Questions
> 
> 1) How can I put the x axis at the top of the plot?

To stop it from being at the bottom:  axes=FALSE in the plot() call.
To draw the box:  box()
To draw an axis on the left:  axis(2).
To draw an axis on the top:  axis(3).

> 
> 2) I am plotting data from a CTD. I want to add series sal, obs and fluo
> at  the same plot by using points(sal,deepth) ets. The data have
> different values so I want to use multiple x axis (4) with different
> scaling. How can I do that?

The axis() function has a variety of arguments to let you place multiple 
axes on one plot.  You'll need to do the rescaling of the data to a 
common scale yourself, then convert the desired tickmarks (which you may 
have obtained from the pretty() function) to that scale.

For example,

x1 <- rnorm(10, mean=10)
x2 <- rnorm(10, mean=100, sd=10)
x2adj <- x2/10
y <- rnorm(10)
plot(x1, y, xlim=range(c(x1,x2adj)), pch="1", axes=F)
box()
axis(2)
ticks <- pretty(x1)
axis(1, at=ticks)
points(x2adj, y, pch="2")
ticks <- pretty(x2)
axis(3, at=ticks/10, labels=ticks)
mtext("x2", side=3, line=3)

> 
> plot(sal,depth,ylim=c(100,0),xlim=c(-0.0120,62),type="l",col.axis="",xaxt="s",xlab="")
> points(temp,depth,type="l",col="red")
> points(obs,depth,type="l",col="green")
> points(fluo,depth,type="l",col="blue")
> 
> Thank you for any help!
> 
> Ener Borg
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list