【问题标题】:Legend symbols for webdings symbols in ggplot2 graphggplot2 图中 webdings 符号的图例符号
【发布时间】:2021-01-09 19:52:32
【问题描述】:

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

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

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

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

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

我想要什么:

【问题讨论】:

  • 有一个older question 没有有效的答案。能够设置geom_point()使用的字体确实非常有用!

标签: r ggplot2 fonts legend geom-text


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2012-12-09
    • 2013-10-27
    • 1970-01-01
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 2014-12-22
    相关资源
    最近更新 更多