-1

I have the following plot where I need to get the blue bar (fail) to the top. I tried with order but it is not making the expected change. What is the issue with the order?

ggplot(a, aes(fill=Var1, y=value, x=Var2, order("pass","fail"))) 
       +geom_bar( stat="identity", position="fill") + labs(x = "Subject", y="Pass/Fail Percentage") 
       + guides(fill=guide_legend(title="Result"))

enter image description here

This is my data

Var1    Var2    value
pass    Maths   865     
fail    Maths   135     
pass    Reading 910     
fail    Reading 90      
pass    Writing 886     
fail    Writing 114
Malintha
  • 4,512
  • 9
  • 48
  • 82

1 Answers1

0

I recommend releveling the factor, like this.

a %>% mutate(Var1 = factor(Var1, levels = c("fail", "pass"))) %>%
  ggplot(aes(fill=Var1, y=value, x=Var2)) + 
  geom_bar( stat="identity", position="fill") + labs(x = "Subject", y="Pass/Fail Percentage") + 
  guides(fill=guide_legend(title="Result"))

enter image description here

Henry Cyranka
  • 2,970
  • 1
  • 16
  • 21