The following R script:
library(ggplot2)
data <- read.csv(text="x,value,version
foo,10,one
foo,12,two
bar,8,one
bar,7,two
baz,11,one
baz,14,two", header=TRUE)
png(filename="so.png")
ggplot(data,aes(data$x,data$value,fill=data$version)) +
geom_bar(stat="identity",position="dodge") +
scale_fill_brewer(palette="Set1") +
labs(x = "x",y="value") +
guides(fill=guide_legend(title="version"))
dev.off()
Produces the following graph:
They appear left to right according to the "x" column (foo, bar, baz) alphabetically. However, I'd like the "x" column-grouped bars to appear according one of the versions, left most being the highest "value" column value. E.g. left to right according to values of "one" version. Thus:
- left most: baz (one:11,two:14)
- middle: foo (one:10,two:12)
- right most: bar (one:8,two:7)
How can I achieve this?