[R] Factors as labels in text() and mtext()

John Maindonald john.maindonald at anu.edu.au
Sat Jun 16 05:24:00 CEST 2001


Currently text() and mtext() give the integer levels in
such contexts as the following:

> f <- factor(letters[1:4])
> plot(1:4, 1:4, type="n")
> text(1:4, 1:4, f)

I presume this was for reasons of S-PLUS compatibility.
However one has
> paste(f)
[1] "a" "b" "c" "d"

where S-PLUS2000 gives "1" in place of "a", etc.
Note that in both dialects, a test for the level
value a is f=="a", not f=="1".

The text() behaviour seems anomalous, especially if one 
is serious about the statement in the draft R language
definition manual (1.2.3) that

"Factors are currently implemented using an integer
array to specify the actual levels and a second array
of names that are mapped to the integers. Rather
unfortunately users often make use of the implementation
in order to make some calculations easier. This . . .
is not guaranteed to hold in all implementations of R."

I presume that the reference is to the use of integers
for the "actual" levels.  Does it imply that sometime
somewhere text(1:4, 1:4, f) might place characters 
other than 1, 2, 3, 4 on the graph?  Or is the current
behaviour of text() and mtext() likely to change in the
future?


John Maindonald               email : john.maindonald at anu.edu.au        
Statistical Consulting Unit,  phone : (6125)3998        
c/o CMA, SMS,                 fax   : (6125)5549  
John Dedman Mathematical Sciences Building
Australian National University
Canberra ACT 0200
Australia
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list