ggplot2图形中的织带符号的图例符号

问题描述

我咨询了许多有用的SO帖子,以帮助我在绘图上放置左右三角形符号。我想指出数据收集的开始和结束。 Webdings字体有一些很好的插入符号,可以解决这个问题:

library(ggplot2)
mydata <- data.frame(x = c(1,2,5,6),y = c(4,4,4),type = c("start","end","start","end"),symbols = c(4,3,3))
ggplot() +
geom_text(data = mydata,aes(x,y,label = symbols),size = 8,family = "Webdings")

enter image description here

但是,我想将图例中的符号 标记为“开始”和“结束”。 有办法轻松做到这一点吗?

我可以尝试使用geom_point而不是geom_text来制作三角形,但是-然后,我不确定如何告诉我的绘图符号应解释为Webdings,而不是常规文本。

ggplot() +
  geom_point(data = mydata,shape = type),size = 8) +
  scale_shape_manual(values = as.character(mydata$symbols))

enter image description here

我想要什么:

enter image description here

解决方法

@Pedro Aphalo的提示帮助我解决了这一问题-谢天谢地Arial字体具有左右指针符号!

我仍然对原始问题(对于其他符号)感兴趣,但这可以满足我的特殊需求。谢谢,佩德罗!

ggplot() +
  geom_point(data = mydata,aes(x,y,shape = type),size = 8) +
  scale_shape_manual(values=c("\u25C4","\u25BA")) 

enter image description here