-
Notifications
You must be signed in to change notification settings - Fork 65
GroupedBarPlot recipe #640
Conversation
|
Sorry that my other PR has stalled a bit. I guess this duplication of effort would have been avoidable. Could you post a screen shot of a plot? Do you implement stacking? (this is done in #580) |
|
Ah I didn't do stacking. Part of my goal was to call I didn't do incremental plotting, either. From reading through yours, it looks like the point is to use So questions to answer:
The latter is what I'm inclined to think is the minimal question before merging. |
|
Why shouldn't stacking and dodging just be keywords in barplot? Is there any downside? (@jkrumbiegel) If we go with a separate recipe, then grouped bar plots should at least cover both stacking and dodging. That is what StatsPlots.jl and ggplot do. The added benefit of your PR with respect to mine is the automatic legend. So what I'd propose is the following.
Of course it's up to @SimonDanisch and @jkrumbiegel to decide. (Simon, I've removed the depency on DataFrames in the other PR so it's ready from my side.) |
|
I don't know, my feeling is that barplot by itself should be simple. But maybe the usability of the all-in-one approach is greater. One factor could be that a GroupedBar recipe might need different conversions than just BarPlot. And that would be annoying or even impossible if the behavior depended on keyword settings, especially because you can change them afterwards. |
I think the arguments against it would be:
If none of these are true it's probably fine to add that functionality directly. |
None of them is true.
Sorry, I don't understand what this means. Would you mind elaborating a bit? |
|
I meant that you might want to convert different inputs differently depending on whether you are constructing a grouped or normal barplot. And the conversion can't depend on a keyword attribute |
|
I see. What do you think, how frequently would that come up? If it's very rare then the work around would be to build a GroupedBar recipe for this particular use case. This will be much simpler than this PR once #580 has landed, right? Also, how is that different from any other keyword in any other recipe? |
|
I've thought a bit more about it, maybe it's not so problematic with the conversions as the critical types would be sent to grouping / stacking attributes anyway. The positional argument types should be the same I guess |
I think we don't have keyword-dependent conversion in any recipe |
|
It will definitely be a different conversion: the natural signature is edit: You could override |
|
In your version, yes, in @greimel's version #580 I think the signatures are still the same. I guess we should converge on one of these sooner rather than later so that nobody wastes time. Currently, I think I'd tend towards the version from @greimel because I suspect now that extending barplot might just be the simplest solution. |
|
Ohhh I see-- when you're coming from DataFrames, it makes sense to have x and y and group_id all same sized vectors. I don't have any real feelings either way about my or @greimel 's version being the more appropriate implementation (though having stacking and grouping at the same time seems nice) but I do feel very strongly that you shouldn't need a DataFrame to plot, so I would strongly advocate for a wrapper around griemel's implementation to allow the signature I use. It's just the natural approach when you're not using a DataFrame (read: I don't want to construct a group identity vector nor duplicate my x vector). I'd be happy to implement that part once griemel's implementation is merged. |
|
would you mind providing the code snippet that generates a plot (including dummy data) your way so that I better understand your approach? |
|
Sure! The above plot is produced by: gbp = groupedbarplot(1:4, [2:5, 3:6, -1:2])
gbp.axis.xticks = 1:4
axislegend(gbp.axis, gbp.plot, ["decent", "best", "worst"])edit: Though don't try to clone and replicate. The code works when external to AbstractPlotting, but not inside of it |
|
In the long-run, this will be supported by AlgebraOfGraphics (using the slicing context) visual(BarPlot) * mapping(1:4, [2:5 3:6 -1:2], dodge = dims(2))This needs #580 to be merged and AlgebraOfGraphics get a non-incremental mode (which might come through https://github.com/greimel/TabularMakie.jl) Implementing this directly would probably be against the Makie philosophy. It can neither plot lines nor grouped scatter plots that way. So there should probably rather be a general solution for grouping. |
|
An additional design consideration is that these features should not be limited to bar plots. Dodging also makes sense for boxplots and violin plots, and stacking also makes sense for the histogram recipe (but maybe that part we get for free with this change), so we should make sure that we can implement all of those without too much code duplication. |
|
as @greimel's version is now merged, I'll close this PR. Thanks for your effort, that certainly helped getting to a good design which I hope has now been found |

A GroupedBarPlot
gbptakesxandgroupsand plots[barplot!(gbp, x .+ offset(group)), group; gbp.attributes..., color=color(group), width=width(group)) for group in groups], calculating the offset, the width, and the color such that the resulting plot has at each value ofxa series of adjacent bars, one for each group ingroups, colored by group identity.Since at its core it just calls
barplot!, all theBarPlotattributes should work as usual, except color and width, which are both overridden to specify a color or width for each group (though a scalar width does fix all the bar widths). Also I overrodeLegendto create an appropriate legend given a list of group labels, but I haven't overriddenlabelto take labels at time of plot creation.TODOs:
labelspecification across groupsLegend, since it doesn't seem to be defined at this point