Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using unicode characters as shape

Tags:

People also ask

How do I use a Unicode character?

Inserting Unicode characters To insert a Unicode character, type the character code, press ALT, and then press X. For example, to type a dollar symbol ($), type 0024, press ALT, and then press X. For more Unicode character codes, see Unicode character code charts by script.

What is the Unicode for a triangle?

Unicode Character “▲” (U+25B2)


I'd like to use unicode characters as the shape of plots in ggplot, but for unknown reason they're not rendering. I did find a similar query here, but I can't make the example there work either.

Any clues as to why?

Note that I don't want to use the unicode character as a "palette", I want each item plotted by geom_point() to be the same shape (color will indicate the relevant variable).

Running

Sys.setenv(LANG = "en_US.UTF-8")

and restarting R does not help. Wrapping the unicode in sprintf() also does not help.

This is an example bit of code that illustrates the problem:

library(tidyverse)
library(ggplot2)
library(Unicode)

p1 = ggplot(mtcars, aes(wt, mpg)) +
  geom_point(shape="\u25D2", colour="red", size=3) +
  geom_point(shape="\u25D3", colour="blue", size=3) + 
  theme_bw()

plot(p1)

And here's what that renders result.

enter image description here

I use macOS Sierra (10.13.6), R version 3.5.1 & Rstudio 1.0.143.

Grateful for any help! I've been scouting several forums looking for a solution and posted to #Rstats, so far nothing has worked. It may be that the solution is hidden in some thread somewhere, but if so I have failed to detect it and I suspect others have also missed it. So, here I am making my first ever post to stack overflow :)