I have been struggling in fixing the legend for a complex ggplot2 plot.
The plot is as follow:
colors = brewer.pal(8, "Dark2")
p <- ggplot(dataf, aes(x = Category)) +
geom_linerange(aes(ymin = low_quantile, ymax = top_quantile),
linetype = 1, color = "#5B9BD5", size = 7) +
geom_point(aes(y = low_quantile, color=low_quantile_plot, shape=low_quantile_plot),
size = 3) +
geom_point(aes(y = top_quantile,color=top_quantile_plot, shape=top_quantile_plot),
size = 3) +
geom_errorbar(aes(y = Mean, ymin = Mean, ymax = Mean,color='Mean'),
lty=1, size=1, width=0.24) +
scale_color_manual(values = c('Mean'='red', 'top_quantile_plot'='green', 'low_quantile_plot'='blue'),
labels = c('Mean', top_quantile_plot, low_quantile_plot)) +
scale_shape_manual(values = c(16, 17)) +
geom_text(aes(x = Category, y = (top_quantile + 10),
label = paste('€', specify_decimal(top_quantile, 2), 'm')))
The problem is with mapping the correct colors and shapes together.
I did not provide the data set, as I would just like to know if the way I'm approaching the ggplot syntax is correct or no.
The output should be the line ranges, with top/low quantile (in different colors and shapes) and the error bar presenting the mean in the middle of the line range (different color).
I'm able to generate the plot correctly, but the problem is with the correct mapping of the legends. At the moment is looks like this, but this is not nice.