[R] Male and female signs as subscript in plot
Prof Brian Ripley
ripley at stats.ox.ac.uk
Mon Jul 1 10:34:57 CEST 2013
On 01/07/2013 09:03, David Winsemius wrote:
> On Jul 1, 2013, at 12:40 AM, Prof Brian Ripley wrote:
>> On 01/07/2013 03:19, Emily Weiser wrote:
>>> I'd like to add labels to my plot that include a male or female symbol as
>>> 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:
>>> 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,
>>> successfully adds an asterisk as a subscript after the word "Male".
>>> 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.
Yes, you could use text() in the margin, in which case (at least on
windows()) you can use \uxxxx notation and don't need Hershey fonts. I
considered mentioning that, but the positioning is going to be really
tricky to do programatically.
>>> 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
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help