使用Unicode字符作为形状 [英] Using unicode characters as shape

查看:139
本文介绍了使用Unicode字符作为形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用unicode字符作为ggplot中图形的形状,但由于未知原因,它们没有呈现.我确实在此处找到了类似的查询>,但我也无法使该示例正常工作.

I'd like to use unicode characters as the shape of plots in ggplot, but for unknown reason they're not rendering. I did find a similar query here, but I can't make the example there work either.

关于为什么的任何线索?

Any clues as to why?

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

Note that I don't want to use the unicode character as a "palette", I want each item plotted by geom_point() to be the same shape (color will indicate the relevant variable).

运行

Sys.setenv(LANG = "en_US.UTF-8")

,然后重新启动R则无济于事.在sprintf()中包装unicode也无济于事.

and restarting R does not help. Wrapping the unicode in sprintf() also does not help.

这是说明问题的代码示例:

This is an example bit of code that illustrates the problem:

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)

这就是结果的呈现.

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

I use macOS Sierra (10.13.6), R version 3.5.1 & Rstudio 1.0.143.

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

Grateful for any help! I've been scouting several forums looking for a solution and posted to #Rstats, so far nothing has worked. It may be that the solution is hidden in some thread somewhere, but if so I have failed to detect it and I suspect others have also missed it. So, here I am making my first ever post to stack overflow :)

推荐答案

使用geom_text代替是否可行?它可以控制字体,因此您可以选择带有所需字形的字体.

Might it work to use geom_text instead? It allows control of the font, so you can select one with the glyph you need.

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()

这篇关于使用Unicode字符作为形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆