I have a matrix with the following entries:
dput(MilDis[1:200,])
structure(list(hhDomMil = c(\"HED\", \"ETB\", \"HED\", \"ETB\", \"PER\",
\"BUM\", \"EXP\",
I see that you have an order
column in your data frame which I gather is your order. Hence you can simply do.
p0 = qplot(factor(kclust), fill = reorder(hhDomMil, order), position = 'fill',
data = df1)
Here are the elements of this code that take care of your questions
reorder
factor(kclust)
factor(kclust)
I remember from a previous question of yours that the hhDomMil
corresponded to different groups, and I suspect your ordering follows the grouping. In that case, you might want to use that information to choose a color palette that makes it simpler to follow the graph. Here is one way to do it.
mycols = c(brewer.pal(3, 'Oranges'), brewer.pal(3, 'Greens'),
brewer.pal(2, 'Blues'), brewer.pal(2, 'PuRd'))
p0 + scale_fill_manual(values = mycols)