4

I've consulted a number of helpful SO posts to help me place right- and left-facing triangle symbols on my plot. I wanted to indicate the start of data collection, and the end of data collection. The Webdings font has some nice caret symbols that do the trick:

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

enter image description here

However, I'd like to label the symbols in my legend as "start" and "end". Is there a way to do this easily?

I could try and make the triangles using geom_point instead of geom_text, but - then I'm not sure how to tell my plot that the symbols should be interpreted as Webdings, not regular text.

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

enter image description here

What I want:

enter image description here

Nova
  • 5,423
  • 2
  • 42
  • 62
  • 1
    There is an [older question](https://stackoverflow.com/questions/48531257/ggplot-geom-point-how-to-set-font-of-custom-plotting-symbols) that has no working answer. Being able to set the font used by `geom_point()` would be very useful indeed! – Pedro J. Aphalo Sep 23 '20 at 16:04

1 Answers1

1

@Pedro Aphalo's hint helped me solve this - thank goodness Arial font has left and right pointer symbols!

I'd still be interested in the original question (for other symbols), but this solved it for my particular needs. Thanks, Pedro!

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

enter image description here

Nova
  • 5,423
  • 2
  • 42
  • 62