Change color inside bars of barplot with ggplot2

Viewed 1903

I have the following barplot, but I can only change the color of the border. No matter what I tried I cannot change the color inside the barplot, which remais gray.

pteddf=data.frame(x=c(0:12),runif(13),runif(13))
tidyr::pivot_longer(pteddf, -x)

colors=c("red", "blue")

ggplot(tidyr::pivot_longer(pteddf, -x),aes(-x,value,color=name,group=name))+
  geom_bar(stat="identity",position=position_dodge())+
  scale_color_manual(name="",labels = c("Negative TED","Positive TED"),
                     values= colors)+
  scale_fill_manual( values = colors)
1 Answers

Try this. You can use fill in the aes() section to change the color of filling:

pteddf=data.frame(x=c(0:12),runif(13),runif(13))
tidyr::pivot_longer(pteddf, -x)

colors=c("red", "blue")

ggplot(tidyr::pivot_longer(pteddf, -x),aes(-x,value,
                                           fill=name,
                                           color=name,group=name))+
  geom_bar(stat="identity",position=position_dodge())+
  scale_color_manual(name="",labels = c("Negative TED","Positive TED"),
                     values= colors)+
  scale_fill_manual(name="",values = colors,
                     labels = c("Negative TED","Positive TED"))

Output:

enter image description here

Related