I've tried to make a plot with the mean specified with a legend and a line at the mean. I used
geom_tile but I want the legend key to look like a line. I don't want a line connecting each group. I tried to specify the
key_glyph but it's not working for
geom_tile and it's just blank.
library(ggplot2) # baseplot p <- ggplot(iris, aes(Species, Sepal.Length)) + geom_dotplot(binwidth=.12, dotsize = .5, binaxis = "y", stackdir='center') + # these are both here to accommodate all examples scale_fill_manual(NULL, values = c(Mean="red")) + scale_color_manual(NULL, values = c(Mean="red")) + theme_bw() # I want this graph p + geom_tile(aes(width=.4, height=.05, fill="Mean"), stat = "summary", fun= mean)
# I want this legend p + geom_line(aes(group=1, color="Mean"), size=3, stat = "summary", fun=mean, key_glyph = draw_key_path) # This is the default
# my failed attempet to copy the key_glyph of geom_line p + geom_tile(aes(width=.4, height=.05, fill="Mean"), stat = "summary", fun = mean, key_glyph = draw_key_path)
Created on 2020-06-10 by the reprex package (v0.3.0)