user13949481
user13949481

Reputation:

R plot not adding plot colors as per documentation?

So I am using a simple dataframe for plotting which looks like:

Category    x
<chr>   <dbl>
2018    2568907
2019    5600309
2020    7488549

And the code I am trying is:

p <- ggplot(df, aes(x=Category, y=x)) + 
  geom_bar(stat = "identity") + scale_color_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))
p

But no matter whether I add scale_color_manual or not, all the bars are shown of same color. However according to documentation I am following, it should be of different colors.

Upvotes: 1

Views: 38

Answers (1)

Duck
Duck

Reputation: 39613

You can try adding a fill or color statement to aes() and then use scale_fill_*() or scale_color_*():

library(ggplot2)
#Code
ggplot(df, aes(x=Category, y=x,fill=Category)) + 
  geom_bar(stat = "identity") +
  scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))

Upvotes: 2

Related Questions