1

I have below code:

  ggplot(aes(x = Education)) + 
  geom_bar(aes(fill = P_3_1, P_3_2)) +
  facet_wrap(~Education) +
  labs(y = 'Qunatity', title = 'Answers for group "P_3" 
       based on education') +
  theme_bw() 

I want to get geom_bar as below with two colours. Is that possible or this part of code: fill = P_3_1, P_3_2 needs to be changed? I'm getting just one coloured gray bars.

enter image description here

  • 1
    Are P_3_1, P_3_2 different variables? Without a minimum reproducible example is difficult to tell https://stackoverflow.com/help/minimal-reproducible-example – RobertoT May 05 '22 at 09:43

1 Answers1

1

It's better if you can provide a small reproducible example like this. Your fill probably needs to be a single column per below?

library(tidyverse)

tribble(
  ~Education, ~quantity, ~fill,
  "a", 1000, "P_3_1",
  "a", 2000, "P_3_2",
  "b", 3000, "P_3_1", 
  "b", 4000, "P_3_2"
) |> 
  ggplot(aes(Education, quantity, fill = fill)) + 
  geom_col() +
  labs(y = 'Qunatity', title = 'Answers for group "P_3" based on education') +
  theme_bw() 

Created on 2022-05-05 by the reprex package (v2.0.1)

Carl
  • 4,232
  • 2
  • 12
  • 24