[R] Male and female signs as subscript in plot

David Winsemius dwinsemius at comcast.net
Mon Jul 1 10:03:21 CEST 2013

On Jul 1, 2013, at 12:40 AM, Prof Brian Ripley wrote:

> On 01/07/2013 03:19, Emily Weiser wrote:
>> Hello,
>> I'd like to add labels to my plot that include a male or female symbol as
>> subscript.
>> I'm working in Windows Vista and R 3.0.0.
>> I am able to add the male symbol to the plot as regular text (NOT as
>> subscript), e.g. with:
>> mtext("Male\u2642")
>> This displays the word "Male" followed by the male symbol on the plot.
>> But "\u2642" does not work when I try to put it as a subscript.
>> For example,
>> mtext(expression("Male"["\u2217"]))
>> successfully adds an asterisk as a subscript after the word "Male".
>> However,
>> mtext(expression("Male"["\u2642"]))
>> displays the word "Male" followed by a subscript of "<U+2642>", i.e. the
>> symbol is not displayed.
>> How can I make the male symbol show as a subscript?
> You cannot use non-native text with plotmath.  The issue is not that you used a subscript but that you passed an expression() call and hence invoked plotmath.  And the help does say
>     In non-UTF-8 locales there is normally no support for symbols not
>     in the languages for which the current encoding was intended.

After discovering in the documentation for ?points, ?plotmath, and ?Hershey that Hershey fonts which do support astrologic symbols cannot be used in plotmath expressions, my suggestion for a work-around is to use plotmath with a phantom() call ofappropriate length in the expression and then two calls to text with xpd=TRUE:

text( locator(1), "\\VE", vfont=c("sans serif","bold"), xpd=TRUE)  # Venus
text( locator(1), "\\MA", vfont=c("sans serif","bold"), xpd=TRUE)  # Mars

I suppose this might work with approapriate modifications to the positioned parameters of that function.

>> Many thanks for any suggestions!
> Read all of ?plotmath.

Agree with Prof Ripley. If you are a bit slow as am I, it may take 3 or 4 readings.

David Winsemius
Alameda, CA, USA

More information about the R-help mailing list