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

Linestyle aes #1181

Merged
merged 2 commits into from
Aug 21, 2018
Merged

Linestyle aes #1181

merged 2 commits into from
Aug 21, 2018

Conversation

Mattriks
Copy link
Member

@Mattriks Mattriks commented Aug 18, 2018

  • I've added an entry to NEWS.md
  • I've updated the documentation to reflect these changes
  • I've added and/or updated the unit tests
  • I've run the regression tests
  • I've squash'ed or fixup'ed junk commits with git-rebase
  • I've built the docs and confirmed these changes don't cause new errors

Linestyle aes

This PR adds:

  1. linestyle as an aesthetic (Feature request aes(linetype=variable)? #455), not just as a Theme field (Dashed Lines #392)
  2. Scale.linestyle_discrete, so 1. & 2. are steps towards Guide.linekey (Legend with Shapes - Colorblind Accessibility #1042)
  3. A new render(geom::LineGeometry) function which fixes Geom.line not drawn after NaNs in SVGs #903, and handles multiple aesthetics smoothly.
  4. Also closes BoundsError with group aesthetic #967, closes BoundsError with plot(fs::Array, a,b, Scale.y_log10) #755

Note that I'll do Guide.linekey in a separate PR.

Examples:

labs = ["exp", "sqrt", "log", "winsor", "linear"]
funcs=[x->60*(1-exp.(-0.2*x)), x->sqrt.(x)*10, x->log.(x)*10, x->winsor(x, prop=0.15), x->x*0.6]
colors = ["α","α","β","γ","γ"] 
x = [1.0:30;]
D = vcat([DataFrame(x=x, y=f(x), linev=l, col=c) for (f,l,c) in zip(funcs, labs, colors)]...)
D[134:136,:y] = NaN

pa = plot(D, x=:x, y=:y, linestyle=:linev, Geom.line, Guide.title("linestyle=:linev"))
# Two aesthetics:
pb = plot(D, x=:x, y=:y, linestyle=:linev, color=:col, Geom.line,
   Scale.linestyle_discrete(levels=["exp", "log", "sqrt", "winsor", "linear"]),
    Guide.title("linestyle≠color"))
# Multiple aesthetics:
pc = plot(dataset("datasets", "CO2"), x=:Conc, y=:Uptake, 
    group=:Plant, linestyle=:Treatment, color=:Type, Geom.line,
    Scale.linestyle_discrete(order=[2,1]),
    Theme(key_position=:top, key_title_font_size=-5mm) )

hstack(pa,pb,pc)

linestyle_a

@tlnagy
Copy link
Member

tlnagy commented Aug 18, 2018

This is awesome. I think the biggest thing would be to have the corresponding legend info like in #1156. Would you prefer to have that in a separate PR?

```@example
using DataFrames, Gadfly, RDatasets
using StatsBase: winsor
set_default_plot_size(18cm, 8cm)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great! the only thing i notice is that all the other gallery examples use 21cm for multi-panel figures and 14cm for single.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll probably expand it to 21cm after I implement Guide.linekey, since a linekey will appear for both plots. For now its 18cm to signify future growth!

@Mattriks
Copy link
Member Author

Yes I'll do Guide.linekey in a separate PR (which I did mention in my original post).

@codecov-io
Copy link

Codecov Report

Merging #1181 into master will decrease coverage by 0.15%.
The diff coverage is 91.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1181      +/-   ##
==========================================
- Coverage   87.33%   87.17%   -0.16%     
==========================================
  Files          34       34              
  Lines        4081     4048      -33     
==========================================
- Hits         3564     3529      -35     
- Misses        517      519       +2
Impacted Files Coverage Δ
src/Gadfly.jl 79.04% <ø> (ø) ⬆️
src/data.jl 0% <ø> (ø) ⬆️
src/aesthetics.jl 82.35% <ø> (ø) ⬆️
src/geom/line.jl 98.07% <100%> (+7.85%) ⬆️
src/geom/hvabline.jl 94.11% <100%> (ø) ⬆️
src/scale.jl 88.26% <100%> (+0.05%) ⬆️
src/geom/polygon.jl 66.66% <100%> (ø) ⬆️
src/geom/segment.jl 94.59% <100%> (ø) ⬆️
src/theme.jl 66.1% <64.28%> (-1.21%) ⬇️
src/misc.jl 51.87% <0%> (-3.75%) ⬇️
... and 2 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 338fe77...180a833. Read the comment docs.

@Mattriks
Copy link
Member Author

I've also tested the strange case in #967 with this PR, and it works:

# baddf.csv from #967
baddf = CSV.read("baddf.csv", allowmissing=:none)
pa = plot(baddf, x=:phi, y=:fhat, color=:i, Geom.line, Scale.color_discrete)
pb =  plot(baddf, x=:phi, y=:fhat, group=:i, Geom.line)
hstack(pa,pb)

linestyle_c

So this PR is ready to merge and will also close #967.

@Mattriks
Copy link
Member Author

Also closes #755:

p2 = plot([sin,cos],0,1, Scale.y_log10, Theme(key_position=:inside)) 

linestyle_d

@bjarthur
Copy link
Member

thanks for this! looks great. i'm going to go ahead and merge, but in future could you please squash your junk commits like the second one here? they just add noise when reading through the commit history, and make things more difficult to revert, cherry-pick, or bisect.

@bjarthur bjarthur merged commit 62f472c into GiovineItalia:master Aug 21, 2018
@tlnagy
Copy link
Member

tlnagy commented Sep 8, 2020

@Mattriks have you had a chance to make the Guide.linekey PR?

@Mattriks
Copy link
Member Author

Not yet, that should go on the next roadmap, after #1385 (which I'm hoping to get back to soon)

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