with a dataframe like below
set.seed(99)
data = data.frame(name=c("toyota", "nissan"), a=sample(1:10,2)/10,b=sample(-150:-50,2),c=sample(1e2:1e3,2),d=sample(1e3:1e5,2), e=sample(-15:30,2))
I'm trying to plot the various variables onto a single chart as below. This works well
library(ggplot2)
library(reshape2)
ggplot(melt(data, id = "name")) +
aes(name, value, fill = name) +
geom_col(position = "dodge") +
facet_wrap(~ variable, scales = "free_y") +
theme(
axis.text.x=element_blank(),
axis.text.y=element_blank()
)
The issue I have is that I want the bars in each facet to be ordered with highest values first - how do I go about this ? Note that I still need to keep the order in legend as it is - that is nissan
, toyota