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

color2 #1436

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

color2 #1436

wants to merge 2 commits into from

Conversation

Mattriks
Copy link
Member

@Mattriks Mattriks commented May 8, 2020

  • I've updated the documentation to reflect these changes
  • I've added an entry to NEWS.md
  • I've added and/or updated the unit tests
  • I've run the regression tests
  • I've built the docs and confirmed these changes don't cause new errors

This PR:

Example

# plot p1 is the same type of plot that reopened #527

iris = dataset("datasets", "iris")
gp = Geom.polygon(preserve_order=true, fill=true)
p1 = plot(iris, x=:SepalLength, y=:SepalWidth, color2=:Species,
    layer(Geom.density2d(levels=[0.1:0.1:0.4;]),  order=1),
    Geom.point, Scale.color_none,  Guide.color2key(title="", pos=[6.9,5.7]), 
    Theme(default_color="gray", point_size=3pt, key_swatch_shape=Shape.circle, 
        key_position=:inside))
p2 = plot(iris, 
    layer(x=:SepalLength, y=:SepalWidth, color2=:Species, alpha=[1.0]),
    layer(x=:SepalLength, y=:SepalWidth, Stat.density2d(levels=7), gp,  order=1,
        Theme(alphas=[0.2],lowlight_color=identity)), Scale.color_continuous,
    Guide.colorkey, Guide.color2key(title="\n\nIris"), 
    Theme(point_size=3pt, key_swatch_shape=Shape.circle, alphas=[0.7],
    lowlight_color=identity), Guide.ylabel(nothing)
)
hstack(p1, p2)

color2

@bjarthur
Copy link
Member

bjarthur commented May 9, 2020

color2 seems like a hack to me. it would be more intuitive to a user i think to permit Guide.colorkey to be used within a layer. how difficult would that be to implement.

@tlnagy thoughts?

@tlnagy
Copy link
Member

tlnagy commented May 9, 2020

Agreed. This might be a pragmatic solution, but associating scales/colorkey with layers seems much cleaner, discoverable, and intuitive.

@Mattriks
Copy link
Member Author

Mattriks commented May 9, 2020

It's not a hack. In Gadfly, aesthetics can be transferred between layers.
How would you do this plot, if there was 1 color aesthetic, and Guides needed to be put in layers?

plot(Coord.cartesian(xmin=0, xmax=5),
    layer(x=0.5:3.5, y=0.5*rand(4), color=0:3),
     layer(x=0.5:3.5, y=rand(4), color=5:8),
    layer(x=1:4, y=rand(4), color2=["Group 1"]),
     layer(x=1:4, y=rand(4), color2=["Group 2"]),
    Theme(point_size=5pt, color2s=[colorant"hotpink", colorant"violet"])
)

color2_layers

@Mattriks
Copy link
Member Author

Mattriks commented May 9, 2020

Also, aesthetic color2 and Scale.color2_discrete follows the suggestion of x2 and Scale.x2_continuous in implementing secondary x,y axes (#373 (comment)) (which @bjarthur gave thumbs up! - and has since removed). Allowing "scales per layer" was seen to be problematic, earlier in that discussion (#373 (comment))

@codecov-io
Copy link

codecov-io commented May 10, 2020

Codecov Report

Merging #1436 into master will decrease coverage by 0.88%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1436      +/-   ##
==========================================
- Coverage   90.26%   89.38%   -0.89%     
==========================================
  Files          39       39              
  Lines        4140     4389     +249     
==========================================
+ Hits         3737     3923     +186     
- Misses        403      466      +63     
Impacted Files Coverage Δ
src/aesthetics.jl 77.77% <ø> (-2.06%) ⬇️
src/data.jl 0.00% <ø> (ø)
src/theme.jl 65.07% <ø> (-4.42%) ⬇️
src/guide/keys.jl 79.86% <69.56%> (-3.19%) ⬇️
src/Gadfly.jl 76.00% <100.00%> (-1.94%) ⬇️
src/geom/point.jl 100.00% <100.00%> (ø)
src/scale.jl 97.58% <100.00%> (+0.08%) ⬆️
src/geom/rectbin.jl 80.55% <0.00%> (-6.95%) ⬇️
src/geom/label.jl 96.26% <0.00%> (-2.74%) ⬇️
... and 24 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 40c708b...36a2555. Read the comment docs.

@bjarthur
Copy link
Member

my thumbs up in #373 was not for y2 but for the ability to have multiple axes in general. there, i agreed with iq2luc's voltage & current plot (as did three others) that the two axes units need not even be convertible. the API needed there needs to be able to handle the case for even more than two axes, as in the OP which had four. i don't think it reasonable to have an x3 and x4 to handle this, as then you'd be limited to a fixed number.

i didn't realize aes could be tranferred btw layers! seems quite useful. nevertheless, from a user perspective, i think a cleaner API would be to permit sth like this:

plot(Coord.cartesian(xmin=0, xmax=5),
     layer(x=0.5:3.5, y=0.5*rand(4), color=0:3),
     layer(x=0.5:3.5, y=rand(4), color=5:8),
     (layer(x=1:4, y=rand(4), color=["Group 1"]),
      layer(x=1:4, y=rand(4), color=["Group 2"]),
      Theme(colors=[colorant"hotpink", colorant"violet"])),
     Theme(point_size=5pt)
)

don't know how hard that would be to implement, but the technical debt taken on by color2 would be too burdensome to refactor later on IMO.

@Mattriks
Copy link
Member Author

That's an interesting suggestion. It looks like a new plot element i.e. SuperLayer <: Element, and a SuperLayer can have its own layers, scales, guides, themes (and there could be some inheritance from 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
4 participants