r - ggplot : some Unicode shapes working while others do not

标签 r ggplot2 unicode

这是一个简单的例子。

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 会产生错误消息

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)

enter image description here

关于r - ggplot : some Unicode shapes working while others do not,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61883118/

相关文章:

java - javadoc 和注释中的 Unicode?

windows - 如何在 Windows 7 上创建 Rscript 的快捷方式

r - 如何在 R 中使用 ggplot 添加 "grouped"标签?

r - 尝试为包创建函数,该函数在存在分类变量时自动绘制给定模型的变量响应

r - 如何替换 geom_text 指南(图例)的图例 'bullet'

unicode - 在哪里可以找到有关字符编码的良好介绍?

python - PyYaml - 转储带有特殊字符(即重音符号)的 unicode

r - 测试R中两个函数的相等性

r - Shiny :单击图像时更改选项卡

r - 基于分类变量,在 R 中从数据框中子集 n 行