ggplot:一些 Unicode 形状可以工作,而另一些则不能

ggplot: some Unicode shapes working while others do not

这是一个简单的例子。

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)

这非常适合创建骷髅头和交叉骨作为形状,如 2620 is the hex value for this unicode character. I actually want the elephant shape, which has the hex code 1F418

但是,用 1F418 替换 2620 会产生错误消息

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

为什么大象造型不行?我怎样才能让大象的形状出现在我的情节中?

小写 \u 转义前缀表示具有 16 位十六进制值的 Unicode 字符。对于 32 位十六进制值,使用大写 \U 或代理对(两个 16 位值):

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

或者:

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