6

Here's a simple example.

library(tidyverse)

dat <- data.frame(x = c(1,2,3,4,5),
  y = c(1,2,3,4,5))

ggplot(dat, aes(x, y)) +
  geom_point(shape="\u2620", size = 8)

This works perfectly to create skull and crossbones as the shapes, as 2620 is the hex value for this unicode character. I actually want the elephant shape, which has the hex code 1F418.

However, substituting 1F418 for 2620 produces the error message

Error: Can't find shape name: * '8'

Why does the elephant shape not work? How can I get the elephant shape to appear in my plot?

Ritchie Sacramento
  • 29,890
  • 4
  • 48
  • 56

1 Answers1

5

The lower case \u escape prefix represents Unicode characters with 16-bit hex values. For 32-bit hex values use the upper case \U or a surrogate pair (two 16-bit values):

ggplot(dat, aes(x, y)) +
  geom_point(shape="\U1F418", size = 8) # is "\U0001f418"

Or:

ggplot(dat, aes(x, y)) +
  geom_point(shape="\uD83D\uDC18", size = 8)

enter image description here

Ritchie Sacramento
  • 29,890
  • 4
  • 48
  • 56