ggplot2 combines glyphs for the same scale which leads to confusing behaviour when using geom_hline and geom_vline to show two perpendicular lines as the key glyph for each color contains a cross (+) rather than | or - in correspondence to that color. How to prevent ggplot from combining - and | key glyphs?
library(ggplot2)
means = as.data.frame(t(colMeans(mtcars)))
(
ggplot(mtcars, aes(x = disp, y = drat))
+ geom_point()
+ geom_hline(data = means, aes(color = 'average disp', yintercept = drat))
+ geom_vline(data = means, aes(color = 'average drat', xintercept = disp))
)
I tried setting key_glyph explicitly for both the geom_vline and geom_hline but it does not change anything.
Note: aside of the ease of interpretation, this is crucial for creating colorblind-friendly plots.


