5

I am trying to figure out how to specify the outline color on a stacked barplot in ggplot2. In the below code I specify color="green", which gives a green outline to each of the bars. I would like to specify a different outline color for each bar (e.g. cut=Fair would be filled with yellow and outlined with orange, cut=Good would be filled with light green and outlined with dark green, etc.).

ggplot(diamonds) +  
  geom_bar(aes(clarity, fill=cut))+
  scale_fill_manual(values=c("Fair"="yellow","Good"="light green","Very Good"="light blue","Premium"="pink","Ideal"="purple"))+

I have tried scale_color_manual() and specifying a vector of colors in the geom_bar() aesthetics, neither have worked.

NobodyNada
  • 7,529
  • 6
  • 44
  • 51
CAT
  • 73
  • 1
  • 5

1 Answers1

4

You must map both aesthetics to the cut variable, and then you can use scale_colour_manual. Here is an (ugly) example:

ggplot(diamonds) +  
  geom_bar(aes(clarity, fill=cut, colour=cut)) +
  scale_colour_manual(values=c("Fair"="brown",
                             "Good"="blue",
                             "Very Good"="green",
                             "Premium"="red",
                             "Ideal"="yellow")) +
  scale_fill_manual(values=c("Fair"="yellow",
                             "Good"="light green",
                             "Very Good"="light blue",
                             "Premium"="pink",
                             "Ideal"="purple"))

enter image description here

nograpes
  • 18,623
  • 1
  • 44
  • 67