Ggplot2: geom_bar stacked barplot, specify outline color

I am trying to figure out how to specify the outline color on stacked tablets in ggplot2. In the code below, I specify color="green"

which gives the green outline of each of the bars. I would like to specify a different outline color for each bar (for example, cut=Fair

will be filled with yellow and highlighted with orange, cut=Good

will 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 tried scale_color_manual()

and set the color vector in aesthetics geom_bar()

and it didn't work.

+3


source to share


1 answer


You have to map both aesthetics to a variable cut

and then you can use scale_colour_manual

. Here's an example (ugly):

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

+2


source







All Articles