0

I want the graphic AVANT to be in first place

dt = data.frame(AVG=c("POT","TPOT"),AVANT=c(5000,4400),APRES=c(5020,6500))
data = gather(dt, key="measure",value="value",c("AVANT","APRES"))
ggplot(data,aes(x=AVG, y=value,fill=AVG))+geom_bar(stat='identity')+facet_wrap(~measure)
A. Suliman
  • 12,923
  • 5
  • 24
  • 37
Aerickk
  • 11
  • 1

2 Answers2

0

You simply need to put measure in a factor with AVANT as the first level to put AVANT to the left of APRES:

data.ordered = mutate(data, measure=factor(measure, levels=c("AVANT","APRES")))
ggplot(data.ordered,aes(x=AVG, y=value,fill=AVG))+geom_bar(stat='identity')+facet_wrap(~measure)
Mosquite
  • 588
  • 1
  • 4
  • 15
0

You may use forcats::fct_rev or more safely forcats::fct_relevel inside fcet_wrap, e.g.

ggplot(data,aes(x=AVG, y=value,fill=AVG)) + geom_bar(stat='identity') + 
facet_wrap(~fct_relevel(measure, c("APRES", "AVANT")))
#facet_wrap(~forcats::fct_rev(measure))
A. Suliman
  • 12,923
  • 5
  • 24
  • 37