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

key for linestyle #1558

Open
bjarthur opened this issue Nov 11, 2021 · 8 comments
Open

key for linestyle #1558

bjarthur opened this issue Nov 11, 2021 · 8 comments

Comments

@bjarthur
Copy link
Member

@Mattriks you've done a lot with the key, but i don't recall if you have plans to work on including linestyle. i have a need for both color and linestyle in the key, and can devote some time to implement. wanted to check with you first though.

using Gadfly, DataFrames
df = DataFrame(y=1:8,
               x=repeat([1, 2], 4),
               c=repeat(["a","b"], inner=4),
               ls=repeat(["c","d"], inner=2, outer=2))
plot(df, x=:x, y=:y, color=:c, linestyle=:ls, Geom.line) |> SVG("test.svg")

Screen Shot 2021-11-11 at 10 17 50 AM

@Mattriks
Copy link
Member

Something that I was working towards (when I use to have time!), was to switch the discrete color aesthetic to use render_discrete_key (#1385), i.e. replace render_discrete_color_key. I would like to get back to that sometime. Yes Guide.linekey is also needed. I haven't thought about the best way to implement, but my first guess would be to make render(guide::LineKey, theme, aes) call render_discrete_key with line shapes. Similar to how Guide.shapekey and Guide.sizekey work. The alternative would be for Guide.linekey to have it's own render_discrete_linekey, but not sure that's preferable than developing render_discrete_key to work with lines.

@DomHin
Copy link

DomHin commented Nov 18, 2021

Will this be done within the next 3-5 months?
I am starting to write my PhD Thesis and this would be very helpful.
Thanks for your work on that @Mattriks :)

@bjarthur
Copy link
Member Author

bjarthur commented Dec 30, 2021

i'm getting some unexpected and inconsistent output when using the shape, size, color, and linestyle aesthetics. i would expect plot(x=[1,2,3,1,2,3], y=[1,2,3,4,5,6], XXX=[1,1,1,2,2,2], Geom.line, Geom.point), where XXX is one of those four aesthetics, to all have two lines, a key, and be discrete, yet each is not so in a different way.

with shape there is just one line:

Screen Shot 2021-12-30 at 11 57 13 AM

with size there is also just one line, and no key:

Screen Shot 2021-12-30 at 11 57 22 AM

with color it is continuous:

Screen Shot 2021-12-30 at 11 57 29 AM

with linestyle there is no key:

Screen Shot 2021-12-30 at 11 57 36 AM

@Mattriks do you concur that these are all bugs? if so, what can we change and still respect semantic versioning?

@bjarthur
Copy link
Member Author

discrete colors is easy of course. just add Scale.color_discrete. what is the argument that this should not be the default when typeof(color)<:Vector{Int}?

Screen Shot 2021-12-30 at 8 51 09 PM

a size key is a bit more cumbersome with Scale.size_discrete2(n->range(3pt, 8pt, length=n)). strange that Scale.size_discrete is not good enough, and that anything extra is needed at all. what is the argument that we can't supply sensible defaults?

Screen Shot 2021-12-30 at 8 51 18 PM

@Mattriks
Copy link
Member

Mattriks commented Jan 5, 2022

Here are some answers to your q's:

what is the argument that we can't supply sensible defaults? (not clear what you mean here)

# Shape applies to points not lines. What shape is a line? 🤔

shape = [1,1,1,2,2,2]
plot(x=[1,2,3,1,2,3], y=[1,2,3,4,5,6], group=shape, shape=shape, Geom.line, Geom.point)

issue1558

@bjarthur
Copy link
Member Author

bjarthur commented Jan 5, 2022

what is the argument that we can't supply sensible defaults? (not clear what you mean here)

it's not intuitive that one automatically gets a key for shape (w/o adding Scale.shape_discrete) but that for size one needs to add a scale. is there a reason for this design? why can't we just automatically include Scale.size_discrete2 if the aesthetic is discrete?

@Mattriks
Copy link
Member

Mattriks commented Jan 5, 2022

The current issue with size is that the default size scale is Scale.size_discrete (or Scale.size_continuous), which does not trigger Guide.sizekey. The plan is to replace Scale.size_discrete with Scale.size_discrete2 in Gadfly 2.0 (see #1376). I mentioned that in ?Scale.size_continuous, but should have also mentioned it in ?Scale.size_discrete . The Tutorial Table also contains useful info about the differences.

@RossBoylan
Copy link

The discussion seems to have expanded and wandered from the title. But that title, and the question

with linestyle there is no key:
...
@Mattriks do you concur that these are all bugs?

is exactly my current concern. The subsequent responses address some the other issues mentioned, but not the basic provision of a key for linestyle that I can see.

It seems even the gallery exhibiting https://docs.juliahub.com/Gadfly/DvECm/1.3.2/gallery/scales/#[Scale.linestyle_discrete](@ref) shows a graph that has nothing on it explaining what the different linestyles mean, i.e., it just illustrates that the feature doesn't work.

I would expect Scale.linestyle_discrete() to produce a little legend that indicated what each type of linestyle meant. That's what I've been looking for in some graphs produced most recently with

plot(pdat, x=, y=:MSEP, color=, linestyle=:pred, Scale.color_discrete(), Geom.line, Scale.linestyle_discrete(order=[1, 2]))

where the values of pred are one of two short strings.

Is this a bug? Perhaps I've misunderstood something.

My example does raise an additional complication, what color (and potentially other aesthetics) to use for the linestyles. I think this is the same issue one would confront if making a legend for shapes, or sizes, or other things the package already manages. I'd be fine with black or even a random selection from the colors used in the plot.

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

No branches or pull requests

4 participants