[R] How to add a top X-axis with a different logarithmic scale?

Itay Furman itayf at fhcrc.org
Thu Mar 25 19:24:54 CET 2004


Hi,

I am trying to put on one plot two different logarithmic
scales, using the bottom and top X-axes.
Below there is an example of what I am trying to achieve,
using axTicks() -- and fails.

I already spent few hours on that, and cannot figure out from
?par and ?axTicks what I am doing wrong.

Example follows:

############################################################

####    Data
x <- c(1.1*1:4, 25*1:5) / 50e+03
y <- c(0.15*1:4, 0.6 + 0.05*1:5)

####    Configure plot
old.par <- par(no.readonly=TRUE)
xlim <- range(xlim)
ylim <- c(0, 1)

####    Plot
## For production I will plot several data sets, so I first
## initialize window, and then use lines().
plot.new()
plot.window(xlim=xlim, ylim=ylim, log="x")
lines(x, y)

####    Plot axes
axis(1)
## Ticks for upper X-axis with a new scale: xlim*4e06
cat("top.ticks:\n", top.ticks <- axTicks(3, usr=xlim*4e06),
    "\n")
## Here I thought to put something like axis(3, at=top.ticks).
## Probably will need to rescale 'top.ticks' according to
## lower X-axis? 
axis(2)

### Restore
par(old.par)

############################################################

Thanks in advance for any comments/suggestions.

	Itay

-----------------------------------------------------------------
itayf at fhcrc.org		   Fred Hutchinson Cancer Research Center




More information about the R-help mailing list