Can I create a custom shape legend when I'm not using geom_point

Hi everyone,

I have used hexagons to mimic texture/pattern on a map drawn with ggplot. These hexagons are added as a sf object (intersection with the map sf object). This is working quite nicely, and I thought I would be able to use scale_shape_manual to create a legend with a white hexagon and a label.

But I can't get it to work. A very simple reprex follows, the map is irrelevant to the query so I've just plotted a line and then want to add a shape legend.

  • I don't want the points to be visible having provided the hexagons elsewhere, but I think the geom_point might be required (colour = NA removes the shape from both the plot and the legend).
  • I thought I could use the unicode horizontal hexagon character, '\u2B23', but it isn't rendering. Font issue? I can't see how I can specify a font for a shape, eg in theme().

Any thoughts?

DF <- tibble(x = c(1, 2), y = c(1, 2), z = 'a')
ggplot(DF, aes(x = x, y = y, shape = z)) +
 geom_line() +
 # 'dummy' geom_point - I don't want the points, just to be
 # able to create a shape legend
 geom_point() +
 scale_shape_manual(values = '\u2B23', label = '<k', name = '')

Created on 2019-03-11 by the reprex package (v0.2.1)


If it is not possible to use scale_shape_manual() to generate a custom legend, could I create a grob and position that outside of the plotting panel, below the fill legend (my maps have fills)?

If so, how would I go about it? Can I find the size of the elements I am mimicking (legend boxes, text etc)? I'm guessing it is in the ggplot object.

But how about positioning?

Just trying to think of alternatives which someone might have experience of.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.