0

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?

Tung
  • 26,371
  • 7
  • 91
  • 115
Visahan
  • 1,130
  • 2
  • 14
  • 35
  • For the kind soul who voted it down, it will be useful if you can also mention the reason so that I can correct myself. I'm new to r, so maybe I have missed something, but just voting it down without mentioning the reason beats the purpose of such Q&A site – Visahan May 12 '18 at 16:48
  • 4
    I guess the reason people downvoted was that you are a long time member yet you didn't provide enough information (data) to make a reproducible problem. See more here [How to make a great R reproducible example?](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Tung May 12 '18 at 18:14
  • Thanks mate, Though I've been in Stack Overflow for quite some time, I'm new to r. Thanks for the helpful link, I'll check it and update my question – Visahan May 13 '18 at 07:22

0 Answers0