 # How to arrange the bars within stacked graphs ?

How can we arrange each bars in such a way that stacked box are arranged in an increasing order rather than random order ?

So, that it is easy to visualize !

Similar questions but this data doesnt consider the counts but the values,
Could not figure how to apply them here.

``````data <- tribble(~type, ~kind, ~percent,
"ABC", "M", 30,
"ABC", "N", 50,
"ABC", "O", 10,
"ABC", "P", 10,
"BCD", "M", 60,
"BCD", "N", 10,
"BCD", "O", 30,
"DEF", "P", 50,
"DEF", "R", 50
)

data %>%
ggplot(aes(x = type, y = percent , fill = kind)) +
geom_col()
``````

This is the graph generated by your code:

1. Can you please specify which order do you want the graph to display?

2. Can you please elaborate what did you mean by `this data doesn’t consider the counts but the values`? I don't really understand this point.

3. Your code doesn't generate the any random order, rather they are in perfect alphabetical order.

4. I may have misunderstood you completely, but if you want different order of `kind`s for different bars corresponding to `type`s, I personally don't think that graph makes much sense. Obviously, I can be wrong here, as it is somehow subjective.

1 Like

Actually, Can we arrange the colrs in 1 particular order for all the bars ?

Eg. ABC should red and top of this brown and then green and blue
Similarly, BCD should also follow the same order depending on which colors it has !

All bars should follow particular order/arrangement
Red > brown > green > blue > Indigo

So that we can see the trend how red is increasing or decreasing from ABC to DEF

Normally, these graphs doesnt consider more than 1 axis and uses count as the value to display the share.
In this case, we have x and y axis instead of just x axis i.e type
(in that case, county will be ABC: 4, BCD: 3, DEF: 2)

That would be the case if you were using `geom_bar()` but `geom_col()` is equivalent to `geom_bar(stat = "identity")`

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.