Skip to content
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

geom_line with colors connects different traces #93

Closed
Tracked by #73
jfb-h opened this issue Apr 25, 2024 · 5 comments · Fixed by #103
Closed
Tracked by #73

geom_line with colors connects different traces #93

jfb-h opened this issue Apr 25, 2024 · 5 comments · Fixed by #103
Labels
bug Something isn't working

Comments

@jfb-h
Copy link

jfb-h commented Apr 25, 2024

If you plot different traces, the start of each trace gets connected to the next. Here's a reproducer:

df = mapreduce(vcat, 1:4) do i 
	DataFrame(
		x=collect(1:100),
		y=cumsum(randn(100)),
		g=fill(string(i), 100)
	)
end

ggplot(df, aes(x=:x, y=:y, color=:g)) + geom_line()

grafik

@jfb-h jfb-h added the bug Something isn't working label Apr 25, 2024
@rdboyes
Copy link
Member

rdboyes commented Apr 25, 2024

Thanks for reporting this - it's another problem (similar to #86) that is downstream from the "ad hoc" way I've handled the idea of "grouping" so far in the package. Hoping to have a fix for this on the way to 0.8.0

@rdboyes rdboyes mentioned this issue Apr 25, 2024
8 tasks
@adknudson
Copy link
Member

I have a MWE of grouping that may be useful. I'm not sure how it's being handled in TidierPlots (somewhere in draw.jl?).

using DataFrames, ColorSchemes, CairoMakie

import Makie.SpecAPI as S

df = DataFrame(
    a = rand(20),
    b = rand(20),
    c = rand(["L", "H"], 20),
    d = rand(["A", "B"], 20),
)

group_df = groupby(df, [:c, :d])

palette = ColorSchemes.tab10

ax = S.Axis()

for (i, key) in enumerate(keys(group_df))
    s = S.Lines(group_df[key].a, group_df[key].b, color = palette[i])
    push!(ax, s)
end

layout_spec = S.GridLayout(ax)
plot(layout_spec)

It seems like the way to do grouping in Makie is to make multiple plot specs.

@rdboyes
Copy link
Member

rdboyes commented May 3, 2024

Thanks @adknudson - this was essentially how I was imagining this would be fixed, but helpful to have a MWE. I added support for geoms that return multiple PlotSpecs when I was fixing geom_smooth (just need to have them return a Vector{PlotSpec} and they should draw automatically). All we need to do is have geoms conditionally return a vector of plotspecs when appropriate and this should work

@rdboyes
Copy link
Member

rdboyes commented May 5, 2024

This is working for geom_path in a dev branch:

image

geom_line isn't currently cooperating - the sort is conflicting with the grouping. Should be fixed soon!

@rdboyes
Copy link
Member

rdboyes commented May 8, 2024

geom_line fixed - will merge soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants