Home > Mobile >  transgendered / hermaphrodite symbol in base R plot (and other rare unicode glyphs - macOs font prob
transgendered / hermaphrodite symbol in base R plot (and other rare unicode glyphs - macOs font prob

Time:01-19

I want to use male/female/transgendered/hermaphrodite symbols in base R plot.

This works for me with male and female symbols (male example below).

a = '\u2642'   # unicode for male (female = '\u2640')
plot(1, 1, pch = a)

male

With hermaphrodite/transgendered, I get a square.

a <- '\u26a5'  # unicode for hermaphrodite/transgendered 
plot(1, 1, pch = a)

hermaphrodite fail

> a
[1] "⚥"

According to what I had read elsewhere, this seemed like it could be a macOs-specific problem. Many other unicodes also failed and gave me the same square.

CodePudding user response:

This is an encoding issue that seems to happen on MacOS or Linux. The solution I find for plotting unicode characters is to use the cairo package.

cairo_pdf("~/Desktop/test2.pdf")
a <- '\u26a5'  # unicode for hermaphrodite/transgendered 
plot(1, 1, pch = a)
dev.off()

When I ran your code I actually received an error:

Warning messages:
1: In plot.xy(xy, type, ...) :
  conversion failure on '⚥' in 'mbcsToSbcs': dot substituted for <e2>

It's interesting you didn't report the same error.

The same issue is observed with ggplot, as it's device/os dependent.

CodePudding user response:

This was resolved by installing fonts that support transgendered/hermaphrodite unicode. A list of fonts reportedly supporting U 26A5 could be found in the link below.

enter image description here

Here, pch could be replaced with likes of main, xlab, ylab, text, etc. There is no need for Cairo - a code for base R shown below works fine.

jpeg("~/Desktop/test2a.jpeg")
a <- '\u26a5' 
plot(1, 1, main = a, family = "Symbola")
dev.off()

Hermaphrodite unicode is supported by few fonts. For most things, Arial Unicode MS works fine. List of characters and glyphs with Arial Unicode MS (38,917 characters and 38,917 glyphs).

http://zuga.net/articles/unicode-all-characters-supported-by-the-font-arial-unicode-ms/

  • Related