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

Manual continuous color legend? #1253

Closed
tlnagy opened this issue Feb 18, 2019 · 4 comments
Closed

Manual continuous color legend? #1253

tlnagy opened this issue Feb 18, 2019 · 4 comments

Comments

@tlnagy
Copy link
Member

tlnagy commented Feb 18, 2019

It would be nice to be able to add a manual color key that is continuous. Guide.manual_color_key only support discrete color scales.

using Gadfly
using Distributions
using ColorSchemes
using Random

n = 1000
Random.seed!(1234)
xs = rand(Normal(0, 1), n)
ys = rand(Normal(0, 1), n)

x_t = cumsum(xs)
y_t = cumsum(ys)
colors = get(ColorSchemes.viridis, collect(1:n-1)./(n-1))

layers = []
for i in 1:n-1
    push!(layers, layer(x=x_t[i:i+1], y=y_t[i:i+1], Geom.line, Theme(default_color=colors[i], line_width=0.5mm)))
end
plot(layers..., Coord.cartesian(aspect_ratio=1.0))

image

@Mattriks
Copy link
Member

I would do the above plot like this:

x, y = cumsum(randn(n)), cumsum(randn(n))
D = DataFrame(x1=x[1:end-1], y1=y[1:end-1], x2=x[2:end], y2=y[2:end], colv=1:n-1)
palettef(c::Float64) = get(ColorSchemes.viridis, c)

p = plot(D, x=:x1, y=:y1, xend=:x2, yend=:y2, 
     color = :colv, Geom.segment, Coord.cartesian(aspect_ratio=1.0),
     Scale.color_continuous(colormap=palettef, minvalue=0, maxvalue=1000)
)

@tlnagy
Copy link
Member Author

tlnagy commented Feb 19, 2019

That's definitely a better way to make this plot, but my nascent feeling is that it could be useful to have a Guide.manual_color_key for continuous color scales too, since we have it already for discrete ones.

@Mattriks
Copy link
Member

The intent of the grammar of graphics is to "map plot aesthetics to data". I think that for a grammar of graphics package manual keys are a good patch while the package is in development, but in the long-term "manual" keys shouldn't be needed. Scales (with mapping functions) and their respective Guides (with title, labels, position etc) is the intent of gog.

@bjarthur
Copy link
Member

that's a beautiful plot! would be great to put it in the gallery as there is currently no Geom.segment entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants