Skip to content

Conversation

@daschw
Copy link
Contributor

@daschw daschw commented Jan 10, 2025

Before these changes

using CairoMakie
using AlgebraOfGraphics
df = (
    x=repeat(1:2, inner=5),
    y=[6, 4, 2, -8, 3, 5, 1, -2, -3, 7],
    group=repeat('A':'E', outer=2),
)
draw(data(df) * visual(Waterfall, show_direction=true) * mapping(:x, :y, color=:group, dodge=:group))

resulted in

ERROR: No aesthetic mapping defined yet for plot type Plot{Makie.waterfall} with scientific eltypes (AlgebraOfGraphics.Continuous(), AlgebraOfGraphics.Continuous()). AlgebraOfGraphics can only use plot types if it is told which attributes and input arguments map to which aesthetics like color, markersize or linewidth for example.
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] aesthetic_mapping(::Type{Plot{waterfall}}, ::AlgebraOfGraphics.Continuous, ::AlgebraOfGraphics.Continuous)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/aesthetics.jl:51
  [3] aesthetic_mapping(plottype::Type, attributes::Dictionaries.Dictionary{…}, scitypes::Vector{…})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/aesthetics.jl:32
  [4] aesthetic_mapping
    @ ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/aesthetics.jl:29 [inlined]
  [5] compute_scale_properties(processedlayers::Vector{ProcessedLayer}, scales::AlgebraOfGraphics.Scales)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/algebra/layers.jl:153
  [6] compute_axes_grid(d::Layer, scales::AlgebraOfGraphics.Scales; axis::Dictionaries.Dictionary{Symbol, Any})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/algebra/layers.jl:252
  [7] compute_axes_grid
    @ ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/algebra/layers.jl:248 [inlined]
  [8] compute_axes_grid(fig::Figure, d::Layer, scales::AlgebraOfGraphics.Scales; axis::Dictionaries.Dictionary{Symbol, Any})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/algebra/layers.jl:218
  [9] compute_axes_grid
    @ ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/algebra/layers.jl:215 [inlined]
 [10] #363
    @ ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/draw.jl:20 [inlined]
 [11] update
    @ ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/draw.jl:10 [inlined]
 [12] plot!(fig::Figure, d::Layer, scales::AlgebraOfGraphics.Scales; axis::Dictionaries.Dictionary{Symbol, Any})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/draw.jl:20
 [13] plot!
    @ ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/draw.jl:16 [inlined]
 [14] (::AlgebraOfGraphics.var"#374#379"{})(f::Figure)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/draw.jl:162
 [15] update
    @ ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/draw.jl:10 [inlined]
 [16] _draw(d::Layer, scales::AlgebraOfGraphics.Scales; axis::Dictionaries.Dictionary{…}, figure::Dictionaries.Dictionary{…}, facet::Dictionaries.Dictionary{…}, legend::Dictionaries.Dictionary{…}, colorbar::Dictionaries.Dictionary{…})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/draw.jl:161
 [17] _draw
    @ ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/draw.jl:154 [inlined]
 [18] draw(d::Layer, scales::AlgebraOfGraphics.Scales; axis::@NamedTuple{}, figure::@NamedTuple{}, facet::@NamedTuple{}, legend::@NamedTuple{}, colorbar::@NamedTuple{}, palette::Nothing)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/draw.jl:85
 [19] draw
    @ ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/draw.jl:75 [inlined]
 [20] draw(d::Layer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/BPWA1/src/draw.jl:75
 [21] top-level scope
    @ REPL[6]:1
Some type information was truncated. Use `show(err)` to see complete types.

Now it produces

waterfall

@jkrumbiegel
Copy link
Member

Thanks! Could you please also add a panel with a stacked version at the bottom of the first reftest?

@daschw
Copy link
Contributor Author

daschw commented Jan 12, 2025

I am not sure if I understand correctly. Do you mean adding a second plot with

data(df) * visual(Waterfall, show_direction=true) * mapping(:x, :y, color=:group, dodge=:group, stack=:group)

?

@jkrumbiegel
Copy link
Member

Yeah just so all aesthetics appear somewhere in the reference tests. I often put multiple in the same plot to save storage space.

@jkrumbiegel
Copy link
Member

Hm I don't really see the stacking :) maybe I'm not sure what a stacked waterfall plot should even look like but I imagined the bars going on top of each other

@daschw
Copy link
Contributor Author

daschw commented Jan 12, 2025

Waterfall plots are stacked anyway - in the sense that a next item starts where the previous one ends. The default stacking group for Waterfall is the same as dodge, so that an item starts, where the item left of it ends. The stack attribute here can be used to choose different stacking groups. I don't know whether there is really a real life use case for this, though :)

@jkrumbiegel
Copy link
Member

Ah ok that does not sound like the typical stack though. That's just a cumsum transformation of sorts on your input data, without that the plot wouldn't be a waterfall at all. Maybe it's best to just leave out that option then.

@jkrumbiegel
Copy link
Member

Huh when I looked at it again just now I noticed that the dodge one is also weird. It removes the x-axis values and instead squeezes both groups into their own "bin" of width 1. Is that the way it's supposed to be?

@daschw
Copy link
Contributor Author

daschw commented Jan 12, 2025

It only has x axis values of 1 and 2. The second plot is one-arg (without x) and hence uses 1 to n as x.

@jkrumbiegel
Copy link
Member

jkrumbiegel commented Jan 12, 2025

Ah ok then I just got confused for a bit, that sounds OK :)

Edit:

No on second thought, it's still weird. Normally when you split by categorical color it's as if you do the same plot multiple times, one per color. Dodging is then used to move each plot so that they can all be seen. But here the colored groups actually interact, the waterfall in the first bin moves across the colors. And then the summary poly goes from the first entry of group 1 to the first of group 5.

@daschw
Copy link
Contributor Author

daschw commented Jan 13, 2025

The way it is was actually the way I intended it when implementing the Waterfall recipe, because this is one of my most used applications of the waterfall plot. However, I see your point that this is not standard dodge behavior just like the stack is not standard stack behavior.
So maybe the dodge in the Makie recipe should not do this magic regrouping stuff, and the behavior I want would be rather a GoupedWaterfall recipe with a group argument doing what dodge does now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants