[R] Symbolic substitution in parallel; use infinity symbol?
John Maindonald
john.maindonald at anu.edu.au
Mon Dec 31 00:45:24 CET 2007
I'd like to be able to modify axlab in (C) below so that 'Inf'
is replaced by the infinity symbol.
y <- rnorm(40)
breaks <- c(-Inf, -1, 1, Inf)
x <- cut(y, breaks=breaks)
plot(unclass(x), y, xaxt="n", xlab="")
## A: The following gives the axis labels "(-Inf, 1]", etc.
axis(1, at=1:3, labels=expression("(-Inf,-1]", "(-1,1]", "(1, Inf]"))
## B: The following replaces Inf by the infinity symbol
axis(1, at=1:3, labels=expression("(" * -infinity * ", " * -1 * "]",
"(" * -1 * ", 1]", "(1, " * infinity
* "]"),
line=1.25, lty=0)
## C: The following gives the axis labels "(-Inf, 1]", etc.,
## in a more automated manner.
axlab <- lapply(levels(x), function(x)substitute(a, list(a=x)))
# Can alternatively use bquote()
axis(1, at=1:3, labels=as.expression(axlab), line=2.25, lty=0)
However I have been unable to modify axlab so that the infinity
symbol appears in place of 'Inf'. Is there is some relatively
straightforward way to do this? The issue is of course more
general than this specific example.
John Maindonald email: john.maindonald at anu.edu.au
phone : +61 2 (6125)3473 fax : +61 2(6125)5549
Centre for Mathematics & Its Applications, Room 1194,
John Dedman Mathematical Sciences Building (Building 27)
Australian National University, Canberra ACT 0200.
More information about the R-help
mailing list