[R] How to get a degree sign into a lattice factor level?
Martin Maechler
maechler at stat.math.ethz.ch
Tue Nov 12 10:46:22 CET 2002
{needing several trials to get this answer through the R-help filters!
please apologize, Sonam! -- MM}
>>>>> "Sonam" == Sonam Lodro <kagyukid at yahoo.com>
>>>>> on Mon, 11 Nov 2002 17:04:57 -0800 (PST) writes:
Sonam> I notice that expressions can be used in legends, but
Sonam> as far as I can tell, cannot be used as levels for
Sonam> factors. I'd like to be able to do something like
Sonam> that so that the levels printed in a lattice plot
Sonam> show the degree character.
Sonam> In Splus, I used to use element [203] (if I remember
Sonam> correctly) of a vector called All.ASCII which could
Sonam> be pasted with text to produce the effect I require.
Sonam> What is a good way to achieve the same in R?
R uses iso-8859-1 (aka "iso-latin1") per default.
Hence the following works ``automatically''
> f4 <- gl(4, 3, labels = paste(10*(0:3),"°", sep=""))
> f4
[1] 0° 0° 0° 10° 10° 10° 20° 20° 20° 30° 30° 30°
Levels: 0° 10° 20° 30°
Now, how do you enter the `°' character ?
I use Emacs and the sequence
`C-x 8 * o'
(In Emacs, type `` C-x 8 C-h '' to get a list of all
``international characters'' you can get with C-x 8 prefixes.
Locally we also use "A-" ("Alt" != Meta) key for entering
things like these; for us particularly the µäöü¢© .. are simple
Alt-key strokes)
The All.ASCII[] vector you found in S-plus actually comes from
Statlib/S-news and was contributed by myself about 10 years ago.
Here is one way to define it {not the shortest at all, but
easiest to understand} :
All.ASCII <-
c("\000", "\001", "\002", "\003", "\004", "\005", "\006", "\007",
"\b", "\t", "\n",
"\013", "\014", "\r", "\016", "\017", "\020", "\021", "\022", "\023",
"\024", "\025", "\026", "\027", "\030", "\031", "\032", "\033", "\034",
"\035", "\036", "\037", " ", "!", "\"", "#", "$", "%", "&", "'", "(",
")", "*", "+", ",", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6",
"7", "8", "9", ":", ";", "<", "=", ">", "?", "@",
LETTERS, "[", "\\", "]", "^", "_", "`",
letters, "{", "|", "}", "~",
"\177", "\200", "\201", "\202", "\203", "\204", "\205",
"\206", "\207", "\210", "\211", "\212", "\213", "\214", "\215", "\216",
"\217", "\220", "\221", "\222", "\223", "\224", "\225", "\226", "\227",
"\230", "\231", "\232", "\233", "\234", "\235", "\236", "\237", "\240",
"\241", "\242", "\243", "\244", "\245", "\246", "\247", "\250", "\251",
"\252", "\253", "\254", "\255", "\256", "\257", "\260", "\261", "\262",
"\263", "\264", "\265", "\266", "\267", "\270", "\271", "\272", "\273",
"\274", "\275", "\276", "\277", "\300", "\301", "\302", "\303", "\304",
"\305", "\306", "\307", "\310", "\311", "\312", "\313", "\314", "\315",
"\316", "\317", "\320", "\321", "\322", "\323", "\324", "\325", "\326",
"\327", "\330", "\331", "\332", "\333", "\334", "\335", "\336", "\337",
"\340", "\341", "\342", "\343", "\344", "\345", "\346", "\347", "\350",
"\351", "\352", "\353", "\354", "\355", "\356", "\357", "\360", "\361",
"\362", "\363", "\364", "\365", "\366", "\367", "\370", "\371", "\372",
"\373", "\374", "\375", "\376", "\377")
-----------
and here are ways to use it
> which(All.ASCII == "°")
[1] 177
> All.ASCII[1:128] # the `proper' ASCIIs
[1] "" "" "" "" "" "" "" "\a" "\b" "\t" "\n"
[12] "\v" "\f" "\r" "" "" "" "" "" "" "" ""
[23] "" "" "" "" "" "" "
" "
" "
" "" " "
[34] "!" "\"" "#" "$" "%" "&" "'" "(" ")" "*" "+"
[45] "," "-" "." "/" "0" "1" "2" "3" "4" "5" "6"
[56] "7" "8" "9" ":" ";" "<" "=" ">" "?" "@" "A"
[67] "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L"
[78] "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W"
[89] "X" "Y" "Z" "[" "\\" "]" "^" "_" "`" "a" "b"
[100] "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m"
[111] "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x"
[122] "y" "z" "{" "|" "}" "~" ""
Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1228 <><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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