23
votes

I want to draw a bar plot with geom_bar where I want unique fill colors surrounded by a black border. However the instruction color="black" is not interpreted as "black" as I want it to be and I get red borders.

library(ggplot2)
test=as.data.frame(cbind(a=c(1,1,2,3), b=1:4, c=as.character(1:4)))
ggplot(test) + geom_bar(aes(x=a, y=b, fill=c, colour="black"), stat="identity")

How do I correctly use geom_bar so that it gives me the correct black border?

1

1 Answers

59
votes

You have to put colour outside aes:

ggplot(test) + geom_bar(aes(x=a, y=b, fill=c), colour="black", stat="identity")

enter image description here