[R] Symbols for male/female

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Thu, 31 Oct 2002 10:54:32 +0100

(diverted to R-devel; I'll send a shorter reply to R-help)

>>>>> "Lorenz" == Lorenz Gygax <gygax@ifi.unizh.ch>
>>>>>     on 31 Oct 2002 08:10:25 +0100 writes:

    Lorenz> Dear all,

    Lorenz> I would like to use the biological symbols for male
    Lorenz> and female as plotting symbols in a scatterplot
    Lorenz> (ideally filled and non-filled). R does not seem to
    Lorenz> have these symbols using pch= in plot() nor are they
    Lorenz> implemented via expression() or at least I did not
    Lorenz> find them. I found that the symbols are
    Lorenz> e.g. available in the wasysym and the marvosym
    Lorenz> package in LaTeX.

    Lorenz> I have coded two very rough functions that are able
    Lorenz> to approximate those symbols, but not surprisingly,
    Lorenz> they are not very efficient regarding the file size
    Lorenz> they produce (I have included the code for the
    Lorenz> female symbol at the end of the mail).

    Lorenz> Is there a more or less straightforward way to
    Lorenz> implement these symbols so that they can be accessed
    Lorenz> either by pch= or expression()? Can you give me some
    Lorenz> pointers on how I would need to go about this?

It's rather "less" than "more" straightforward ;-) : 

In src/main/graphics.c, you look for the function GSymbol().
There, you see how each (pch = <integer>) symbol is done.
In principle, you just would add new case statements;
pch = 26 and pch =27  would be the next free ones ...

Probably you need to poke around a bit in the C source of R in
order to learn how to do this.
In this case, the source is the documentation.

There have been wishes and dreams about using something like
  pch = <<pointer to (jpg|pdf|eps|png|...) file>>
which of course would be much more general and useful, but
needs much more work of course!
Maybe rather something that would only be done in the new
graphics system which the grid package provides ?
Greetings up the hill (in Zürich)!

Martin Maechler <maechler@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			<><

    Lorenz> Thanks and regards, Lorenz
    Lorenz> -- 
    Lorenz> Lorenz Gygax, Dr. sc. nat.
    Lorenz> Artificial Intelligence Lab, Department of Information Technology
    Lorenz> University of Zurich-Irchel, +41-1-635 67 17,  gygax@ifi.unizh.ch

    Lorenz> one.female <- function (X, diam= 1, prop= 1, lw= 1) {
    Lorenz> ## X a vector giving the position of the symbol c (x, y)
    Lorenz> ## diam: diameter in the entities on the Y axis
    Lorenz> ## prop: proportion of x to y axis (so that symbols will be round
    Lorenz> ## lw: adjustment of line width for large symbols

    Lorenz> x.ring <- cos (seq (0, 2*pi, len= 500)) * prop * diam/2
    Lorenz> y.ring <- sin (seq (0, 2*pi, len= 500)) * diam/2
    Lorenz> lines (x.ring + X[1], y.ring + X[2], lwd= lw)
    Lorenz> segments (c (0, -diam/4) + X[1],
    Lorenz> c (-diam/2, -3*diam/4) + X[2],
    Lorenz> c (0,  diam/4) + X[1],
    Lorenz> c ( -diam , -3*diam/4) + X[2], lwd= lw)
    Lorenz> }

    Lorenz> and to plot several iteams at a time

    Lorenz> female <- function (x, y, d= 1, p= 1, l= 1) {
    Lorenz> ## x, y vectors of x and y coordinates
    Lorenz> ## d: diameter
    Lorenz> ## p: proportion of symbol
    Lorenz> ## l: line width

    Lorenz> xy <- cbind (x, y)
    Lorenz> apply (xy, 1, FUN= one.female, diam= d, prop= p, lw= l)
    Lorenz> }
r-devel 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-devel-request@stat.math.ethz.ch