-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dodge in scatter,lines #393
Comments
ok - I needed this again and couldnt find a solution. I implemented a new Makie Recipe Please find the gist here: https://gist.github.com/behinger/8df41a3e051979a8e8ee0068f1aac6b8 I don't really know whether I also dont know if this is the nicest way, but one can dodge all kinds of plots. tried with scatter and errorbars. dodging in y instead of x is supported as well. MWE begin
using Makie
using CairoMakie
using HTTP
HTTP.download("https://gist.githubusercontent.com/behinger/8df41a3e051979a8e8ee0068f1aac6b8/raw/4c6f44603d4432b19c8abe2955eab4962a8ae45f/MakieDodge.jl",tempdir()) |>include
#----
x = [1,2,3, 1,2,3., 3,2,1]
y = [1.1,1.9,2.8,1,2,3,3.05,2.05,1.05]
c = ["red","red","red","green","green","green","blue","blue","blue"]
low,high = repeat([0.2],length(x))
dodge(x,y,low,high;plot_fun=errorbars!,color=c)
dodge!(x,y;color=c, plot_fun=scatter!)
current_figure()
end |
let
d = DataFrame(:x=>["x2","x1","x2","x1","x3","x3","x4"],:y=>[2.,1.1,2.1,1.,3.,3.1,4],:c=>["a","a","b","b","b","b","b"])
d.high = repeat([0.1],nrow(d))
d.low = repeat([0.1],nrow(d))
data(d)*
mapping(color=:c,dodge=:c) *
(
mapping(:x,:y,:low,:high,)* visual(Dodge,plot_fun=errorbars!) +
mapping(:x,:y) * visual(Dodge)
) |> draw
end |
@jkrumbiegel I would be super interested in this feature! Not sure how to add it. But if it could go higher on the priority list I would appreciate it! |
I'm not sure, yet, either, how exactly this could be implemented. But in principle one can add arbitrary keywords to the aesthetic mapping of a plotting function, which just have to be removed before everything is transferred to Makie. Maybe one could add some sort of generic logic to AlgebraOfGraphics.jl/src/algebra/layers.jl Lines 314 to 351 in a61e361
|
I think the issue is that Makie itself has no concept of dodge for certain things like lines and errorbars. So this has to be fixed upstream, right? |
Well as I wrote above, if you consider dodging in data space, then you don't really have to add it to plotting functions. You could, but you don't have to, depending on what exactly is plotted and whether there's some advanced interactions like in barplots where width needs to change as well. |
Yes sorry, my particular application is bar plots with error bars on the top. |
As a concrete example, here is what I want to be able to do with AoG:
I get
|
Problem description
I often encountered the issue, that there is no way to dodge datapoints in a scatter (or less important imho line) plot.
That is going from here:
To here:
Something similar is asked here #230 I think
Proposed solution
I dont understand enough of the internals, but as I understand Makie.jl implements the dodge feature for violin & histograms.
In ggplot2 dodging is possible by specifing a position-function (
position = position_dodge(width=0.2)
). I was expecting something likedata(df) * mapping(x,y,color="categoryA",dodge="categoryA") * visual(Scatter)
to "just work", by doding the colored datapoints.Let's just hope I missed something ;-)
The text was updated successfully, but these errors were encountered: