I'm plotting a bar graph of my data, where I show my categorized data vs it's frequency. I wanted to highlight the minimum and maximum values, so my code looks like
library(ggplot2)
ggplot(df, aes(val, Count)) +
geom_bar(stat = 'identity', fill = " #ff1a1a") +
geom_bar(data=subset(df, Count==min(Count)), aes(val, Count), fill="#ffb366", stat="identity") +
geom_bar(data=subset(df, Count==max(Count)), aes(val, Count), fill="#66ff66", stat="identity")
I'm unable to add a legend to it to show that one color signify max and one signifies min. I tried adding scale_colour_manual but it did not work
cols <- c("Min"="#ffb366","Max"="#66ff66")
ggplot(df, aes(val, Count)) +
geom_bar(stat = 'identity', fill = " #ff1a1a") +
geom_bar(data=subset(df, Count==min(Count)), aes(val, Count), fill="#ffb366", stat="identity") +
geom_bar(data=subset(df, Count==max(Count)), aes(val, Count), fill="#66ff66", stat="identity")
scale_colour_manual(name="Bar info",values=cols)
Is there a solution for this?