[6434] in s-news-athena
A little function to add minor tick marks
daemon@ATHENA.MIT.EDU (Frank Harrell)
Tue Feb 14 09:40:00 1995
From: Frank Harrell <feh@biostat.mc.duke.edu>
To: s-news@utstat.toronto.edu
Date: Tue, 14 Feb 1995 09:05:00 -0500 (EST)
This function adds minor tick marks to an existing plot. As an aside,
the graphics 'experts' seem to use minor tick marks sparingly.
minor.tick <- function(nx=2, ny=2, tick.ratio=.5) {
ax <- function(w, n, tick.ratio) {
range <- par("usr")[if(w=="x") 1:2 else 3:4]
tick.pos <- if(w=="x") par("xaxp") else par("yaxp")
#Solve for first and last minor tick mark positions that are on the graph
distance.between.minor <- (tick.pos[2]-tick.pos[1])/tick.pos[3]/n
possible.minors <- tick.pos[1]-(1:100)*distance.between.minor
low.minor <- min(possible.minors[possible.minors>=range[1]])
if(is.na(low.minor)) low.minor <- tick.pos[1]
possible.minors <- tick.pos[2]+(1:100)*distance.between.minor
hi.minor <- max(possible.minors[possible.minors<=range[2]])
if(is.na(hi.minor)) hi.minor <- tick.pos[2]
axis(if(w=="x") 1 else 2, seq(low.minor,hi.minor,by=distance.between.minor),
labels=F, tck=par("tck")*tick.ratio)
}
if(nx>1) ax("x", nx, tick.ratio=tick.ratio)
if(ny>1) ax("y", ny, tick.ratio=tick.ratio)
invisible()
}
Here's the .Help file:
.tr @@
.BG
.FN minor.tick
.TL
Minor Tick Marks
.DN
Adds minor tick marks to an existing plot. All minor tick marks that
will fit on the axes will be drawn.
.CS
minor.tick(nx=2, ny=2, tick.ratio=0.5)
.OA
.AG nx
number intervals in which to divide the area between major tick marks on
the X-axis. Set to 1 to suppress minor tick marks.
.AG ny
same as `nx' but for the Y-axis
.AG tick.ratio
ratio of lengths of minor tick marks to major tick marks. The length
of major tick marks is retrieved from `par("tck")'.
.SE
plots
.SH AUTHOR
Frank Harrell
.sp 0
Division of Biometry
.sp 0
Duke University Medical Center
.sp 0
feh@biostat.mc.duke.edu
.SA
`axis'
.EX
plot(x, y)
minor.tick()
.KW aplot
.KW hplot
.WR
For Dos/Windows users here's a formatted Help file:
Minor Tick Marks
DESCRIPTION:
Adds minor tick marks to an existing plot. All minor tick
marks that will fit on the axes will be drawn.
USAGE:
minor.tick(nx=2, ny=2, tick.ratio=0.5)
OPTIONAL ARGUMENTS:
nx: number intervals in which to divide the area between major
tick marks on the X-axis. Set to 1 to suppress minor tick
marks.
ny: same as nx but for the Y-axis
tick.ratio: ratio of lengths of minor tick marks to major tick
marks. The length of major tick marks is retrieved from
par("tck").
SIDE EFFECTS:
plots
AUTHOR:
Frank Harrell
Division of Biometry
Duke University Medical Center
feh@biostat.mc.duke.edu
SEE ALSO:
axis
EXAMPLES:
plot(x, y)
minor.tick()