在R的ggplot文本中添加箭头符号 [英] Adding arrow symbols in ggplot text in R

查看:1127
本文介绍了在R的ggplot文本中添加箭头符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现,可以在ggplot的带注释的文本内添加希腊字母和其他符号。我正在尝试在文本中添加箭头(向上和向下),但似乎找不到正确的数字代码。我尝试搜索,但无法在线找到代码列表。语法类似于标签下的语法:

  label ='test text'* symbol('\\205' ) 

\142为beta符号,\154为伽玛符号。有谁知道此代码如何工作?谢谢!

解决方案

以下作品:

  ggplot(mpg,aes(displ,hwy))+ 
geom_point()+
geom_smooth(aes(colour = loess),method = loess,se = FALSE) +
geom_smooth(aes(colour = lm),method = lm,se = FALSE)+
labs(colour = Method)+
annotate( text, x = 3.5,y = 35,label = sprintf('\u2191'))+
geom_curve(aes(x = 4,y = 30,xend = 3.5,yend = 34),
颜色=#FF0000,
大小= 0.5,
曲率= -0.2,
箭头=箭头(长度=单位(0.03, npc)))+
geom_label( aes(x = 4,y = 31,label =这是nUnicode符号),
hjust = 0,
vjust = 0.5,
color =#FAAB18,
fill = white,
label.size = NA,
family = Helvetica,
size = 6)

Unicode箭头f rom


I recently found out that it is possible to add greek alphabets and other symbols within the annotate text in ggplot. I am trying to add arrows (upwards and downwards) to my text and I can't seem to find the correct numerical code for it. I tried searching but can't find a list of codes online. The syntax is something like that under label:

label="'test text ' * symbol('\\205')"

\142 gives a beta symbol and \154 gives a gamma symbol. Anyone knows how does this code works? Thanks!

解决方案

The following works:

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  geom_smooth(aes(colour = "loess"), method = "loess", se = FALSE) +
  geom_smooth(aes(colour = "lm"), method = "lm", se = FALSE) +
  labs(colour = "Method") +
  annotate("text", x = 3.5, y = 35, label = sprintf('\u2191')) +
  geom_curve(aes(x = 4, y = 30, xend = 3.5, yend = 34), 
             colour = "#FF0000", 
             size=0.5, 
             curvature = -0.2,
             arrow = arrow(length = unit(0.03, "npc"))) +
  geom_label(aes(x = 4, y = 31, label = "Here is the\nUnicode symbol"), 
             hjust = 0, 
             vjust = 0.5, 
             colour = "#FAAB18", 
             fill = "white", 
             label.size = NA, 
             family="Helvetica", 
             size = 6)

Unicode for arrows from here

Here is the resulting plot:

这篇关于在R的ggplot文本中添加箭头符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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