With a data frame df
like below, I'm plotting bar plots with faceting.
text <- "
make,var,value
fiat,mileage,2.1
astom,mileage,1.8
fiat,disp,1.4
astom,disp,1.7
"
df <- read.table(textConnection(text), sep = ",", header = TRUE)
ggplot(df, aes(x=make, y=value) ) +
geom_bar(stat = 'identity') +
facet_wrap(~ var, scales = "free", ncol=1)
This gives a plot like below.
However, I want x-axis labels to be ordered in descending order of the value of the var
- in the example above for the mileage
var, fiat
should be shown before astom
- how do I got about it ?