I wish I could sort the values for each facet in descending order.
I used reorder (Agent, -value)
but it doesn't work.
A part of my data :
Country Agent Period Level Location variable value
361 e L 2016_2017 1 d 11 8
362 e S 2016_2017 1 d 11 1
363 e C 2016_2017 1 d 11 12
364 e B 2016_2017 1 d 11 6
365 e A 2016_2017 1 d 11 5
366 e D 2016_2017 1 d 11 2
My simplified code :
library(ggplot2)
# toy data
data = data.frame(Country = c("e","e","e","e","e","e","e","e","e","e","e","e"),
Agent = c("L","S","C","B","A","D","L","S","C","B","A","D"),
Period = c("2016_2017","2016_2017","2014_2015","2014_2015","2011_2012","2011_2012","2016_2017","2016_2017","2014_2015","2014_2015","2011_2012","2011_2012"),
Level = c("1","1","1","1","1","1","1","1","1","1","1","1"),
Location = c("d","d","d","d","d","d","d","d","d","d","d","d"),
variable = c("11","11","11","11","11","11","21","21","21","21","21","21"),
value = c(8,1,12,6,5,2,4,6,1,0,6,3))
# most importants parts of my plot, related to the question
ggplot(data, aes(x = reorder (Agent, -value), y = value)) +
geom_bar(position = "dodge", stat = 'identity') +
facet_grid(Period~variable, scales = "free", space="free")
Here is the ouput of my full code: