I recently asked a question here which allowed me to add borders to geom_point()
s in ggplot2
with customizable colors and thickness. Admittedly, it's a bit of a hack and I'm now having some trouble which may be a result of this. The borders are generated by layering two geom_point()
s, one of which is the color of the border that I want and which is slightly larger than the geom_point()
which provides the "fill". A reproducible example here:
require('ggplot2')
values <- rnorm(n = 10, mean = 1, sd = 0.5) + c(1:10)
df <- data.frame(id = rep(c('hq', 'lq'), each = 5),
values = values,
period = rep(c(1:5), 2))
plot <-
ggplot(df, aes(x = period,
y = values,
group = id,
shape = id,
color = id)) +
geom_line(color = 'gray40') +
geom_point(color = 'gray24',
size = 4) +
geom_point(size = 3) +
guides(shape = guide_legend(override.aes = list(size = 5))) +
scale_color_manual(values = c('lightskyblue1', 'lightpink'),
labels = c('HQ', 'LQ')) +
scale_shape_manual(values = c(15, 17, 0, 2),
labels = c('HQ', 'LQ')) +
theme_bw()
Because I would like the legend symbols to be larger than the plot symbols, I've used override.aes()
. However, this means that the "borders" I've created do not appear in the legend:
Is there some way to give multiple size
arguments to override.aes()
so that the layering I've used in the plot is left intact in the legend (i.e. the legend symbols also contain the "borders")?