0

I'm producing a stacked bar plot with purple and yellow but the two colours won't show up. Here is my code:

ggplot(df_group, aes(x = COLOUR, y =COUNT, fill = GROUP,label=GROUP)) +
  geom_bar(position="stack", stat = "identity") +
  scale_fill_manual("Flower Colour", values = c("Purple" = "mediumpurple", "Yellow" = "Gold")) +
  labs(x='Group', y="Visits")

What do I need to change?

enter image description here

Skaqqs
  • 4,010
  • 1
  • 7
  • 21
  • 1
    Change `fill = GROUP` to `fill=` whatever field in `df_group` contains "Purple" and "Yellow" – Skaqqs May 20 '22 at 18:36
  • It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick May 20 '22 at 18:41
  • Look like it should be `fill=COLOUR` and `x=GROUP`... But I agree with MrFlick – Skaqqs May 20 '22 at 18:43

1 Answers1

0

I suspect that your code could not have created that plot. Your aesthetics are swapped around. Try this:

df <- data.frame(
  COUNT = runif(n = 20, min = 0, max = 10),
  GROUP = sample(c("bee", "beetle", "butterfly"), 20, replace = TRUE),
  COLOUR = sample(c("Purple", "Yellow"), 20, replace = TRUE))

ggplot(df, aes(x = GROUP, y = COUNT, fill = COLOUR)) +
  geom_bar(position = "stack", stat = "identity") +
  scale_fill_manual("Flower Colour", values = c("Purple" = "mediumpurple", "Yellow" = "Gold")) +
  labs(x='Group', y="Visits")

enter image description here

Skaqqs
  • 4,010
  • 1
  • 7
  • 21