I am working on stack barchart and here is the test code :
dat <- read.table(text="
cars trucks suvs
10 40 25
20 20 35
30 15 25
50 25 30
20 30 15", header=TRUE, as.is=TRUE)
dat$day <- factor(c("Mo", "Tu", "We", "Th", "Fr"),
levels=c("Mo", "Tu", "We", "Th", "Fr"))
library(reshape2)
library(ggplot2)
mdat <- melt(dat, id.vars="day")
head(mdat)
ggplot(mdat, aes(variable, value, fill=day)) +
geom_bar(stat="identity", position="stack")+coord_flip()
What I want is : i would like to know if i can change the order of the group factors (dat$day) for each variable in the plot. The goal is to have the same barchart with different order color for each variable. Changing the color order is not hard but different order is a different story. Indeed, i want to have the first color assign to the biggest value for each variable.
i hope i was enough specific. Thanks in advance.