使用unicode字符作为形状

Las*_*vig 9 unicode r ggplot2

我想在ggplot中使用unicode字符作为绘图的形状,但由于未知原因它们不会渲染.我确实在这里找到了类似的查询,但是我也无法使这个例子工作.

任何线索为什么?

请注意,我不想将unicode字符用作"调色板",我希望绘制的每个项目geom_point()都是相同的形状(颜色将指示相关变量).

运行

Sys.setenv(LANG = "en_US.UTF-8")
Run Code Online (Sandbox Code Playgroud)

并重新启动R没有帮助.在sprintf()中包装unicode也没有用.

这是一个示例代码,用于说明问题:

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)
Run Code Online (Sandbox Code Playgroud)

这就是结果.

在此输入图像描述

我使用macOS Sierra(10.13.6),R版本3.5.1和Rstudio 1.0.143.

感谢任何帮助!我一直在寻找一些寻找解决方案并发布到#Rstats的论坛,到目前为止没有任何效果.可能是解决方案隐藏在某个地方的某个线程中,但如果是这样,我就无法检测到它,我怀疑其他人也错过了它.所以,在这里,我正在制作我的第一篇文章,以堆栈溢出:)

Jon*_*ing 5

使用它可能会起作用geom_text吗?它允许控制字体,因此您可以选择具有所需字形的字体。

library(tidyverse)
ggplot(mtcars, aes(wt, mpg)) +
  geom_text(label = "\u25D2", aes(color = as.character(gear)),  
            size=10, family = "Arial Unicode MS") +
  geom_text(label = "\u25D3", colour="blue", 
            size=10, family = "Arial Unicode MS") + 
  scale_color_discrete(name = "gear") +
  theme_bw()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

  • 我需要使用“Lucida Sans Unicode”才能使其正常工作,因为我的系统没有安装“Arial Unicode MS”。 (2认同)