ggplot:某些Unicode形状有效,而另一些则不起作用

问题描述 投票:3回答:1

这是一个简单的例子。

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。我实际上想要elephant shape, which has the hex code 1F418

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

错误:找不到形状名称:*'8'

为什么大象形状不起作用?如何使大象形状出现在我的绘图中?

r ggplot2 unicode
1个回答
3
投票

[小写\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)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.