3

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
    Does this answer your question? [Change bar plot colour in geom\_bar with ggplot2 in r](https://stackoverflow.com/questions/38788357/change-bar-plot-colour-in-geom-bar-with-ggplot2-in-r) – holzben Jan 11 '21 at 19:29

1 Answers1

2

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

Duck
  • 39,058
  • 13
  • 42
  • 84