StatsPlots.jl icon indicating copy to clipboard operation
StatsPlots.jl copied to clipboard

Groupedbar x axis order

Open mkborregaard opened this issue 7 years ago • 6 comments

In Groupedbar we can change the order withing groups by making them a categorical variable and changing the levels. It's a little circumspect, but it works. But we can't do that with the order of the groups (specified by x). That would be great to have.

mkborregaard avatar Aug 23 '18 15:08 mkborregaard

Related, always from the discourse thread:

we could probably allow to use groupedbar(["a", "a", "b", "b"], [1,2,3,4]) to give the same plot as groupedbar(["a", "b"], [1 2; 3 4]), currently it errors.

piever avatar Aug 25 '18 17:08 piever

@mkborregaard Do you have an example of using categorical variables to reorder within groups? I tried using CategoricalArrays.jl, but this doesn't seem to be working.

darsnack avatar Jul 12 '19 18:07 darsnack

Also to follow up for those who are struggling with the same issue, I have found that using replace! to add a series of spaces before words you want to appear first works as a brutal hack. I think Plots.jl actually trims the white space before displaying it in the plot, but internally for ordering, the spaces are respected by <, >, etc.

Works if you don't have many issues with the lexical order, but a pain otherwise.

darsnack avatar Jul 12 '19 18:07 darsnack

Any luck with this? (or any working workaround? the space thing does not work (spaces are preserved in the legend)

nico202 avatar Nov 08 '19 16:11 nico202

Yeah spaces trick only worked when plotting in IJulia, but spaces were preserved when saving to file. I have not found any other work around.

darsnack avatar Nov 08 '19 20:11 darsnack

I gather no updates on this?

An option which makes the plot command respect the dataframe order for x would be really nice, as that would simply allow !sort (or any other method) to arrange the dataframe in the desired order for plotting instead of the alphabetical x sort that occurs now.

dpgarrick avatar Mar 20 '21 00:03 dpgarrick