I am trying to plot a line segment with an arrow on the end, and make it appear in the legend. I can do this with the following code:
library(ggplot2)
# sample data
dat <- data.frame(
x = as.factor(1:10),
y = c(20,30,13,37,12,50,31,2,40,30),
z = rep('a', 10)
)
# basic plot
ggplot(dat) +
geom_segment(
aes(x = x, xend = x, y = 0, yend = y+15, linetype = z),
arrow = arrow(length = unit(0.25, 'cm'), type = 'closed'),
size = 0.7
)
output:
issue:
My issue is that the arrow in the legend is not solidly filled like the plot is. I have tried using guide_legend(override.aes = aes(fill='black'))
and guide_legend(override.aes = aes(type='closed'))
but neither had any effect on the legend.
Does anyone know how to make the triangle be filled in and solidly black?
edit:
I have a similar issue with geom_label
not including the black line around the label in the legend. I managed to get around this by adding a geom_rect
in the exact position I want, but hopefully that's not the best solution :P
Any solution to either would be very helpful!