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

Disappointing Behavior with colors and Guide.manual_color_key #940

Open
Nosferican opened this issue Dec 16, 2016 · 11 comments
Open

Disappointing Behavior with colors and Guide.manual_color_key #940

Nosferican opened this issue Dec 16, 2016 · 11 comments
Labels

Comments

@Nosferican
Copy link

Guide.manual_color_key renders an additional legend instead of replacing the default one from colors.
screenshot 2016-12-16 14 47 21

@tlnagy
Copy link
Member

tlnagy commented Dec 16, 2016

Can you post a minimal code example for us to reproduce?

@Nosferican
Copy link
Author

Here it is:

using DataFrames
using RDatasets
using Gadfly
iris = dataset("datasets", "iris")

Using color as usual:

Plot = plot(iris, x = :SepalWidth, y = :SepalLength, color = :Species, Geom.point)

Now I attempt to use Guide.manual_color_key along color.

Plot = plot(iris, x = :SepalWidth, y = :SepalLength, color = :Species, Geom.point,
Guide.manual_color_key("Not Species", ["setosa?", "versicolor?", "virginica?"],
["red", "green", "blue"]))

I suggest that Guide.manual_color_key replace the legend at all or add an option to either modify the one by color or replace it completely (the default behavior).

@Mattriks
Copy link
Member

How about:

cscale = Scale.color_discrete_manual(colorant"red", colorant"green", colorant"blue")
p = plot(iris, x = :SepalWidth, y = :SepalLength, color = :Species, Geom.point, 
    cscale, Guide.colorkey("Iris")
)

See Guide.manual_color_key for an example of the sort of plot its designed for.

@Nosferican
Copy link
Author

That's one alternative. I needed to change the label values as well to a string that it is not supported for column names in data frames so defining the Scale.color_discrete_manual would not be a complete solution for me, e.g. (p = 0.25). I ended up having to do the long way and make a layer for each one so I could use the Guide.manual_color_key and not depend on color to create the individual geoms for each group of y.

@Mattriks
Copy link
Member

So the issue here seems to be what to do about difficult factor/level/label names in DataFrames. The suggestion here is to change the factor/level/label names after the dataframe has been converted to long format. For example:

d = Dict{String,String}("setosa"=>"p=0.1","versicolor"=>"p=0.2", "virginica"=>"p=0.3")
# Add a new variable to the dataframe:
iris[:g] = map(x -> d[x], iris[:Species])

p = plot(iris, x = :SepalWidth, y = :SepalLength, color = :g, Geom.point, 
    cscale, Guide.colorkey("Iris")
)

@Nosferican
Copy link
Author

I like that approach as it is a good workaround and in many cases preferred to creating the different layers. However, I still think it is worthy to address the compatibility issue between color and Scale.color_discrete_manual and the double legend issue.

@xiaohk
Copy link

xiaohk commented Jan 4, 2017

Yes, I agree with @Nosferican. It would be great if Guide.manual_color_key can overwrite the color key legend generated by color or Scale.color_discrete_manual .

@Nosferican
Copy link
Author

Any updates on this front? An alternative would be to have the Theme(key_position::Symbol = :right) accept a vector of positions matching the number of legends. That way, one can potentially suppress any or display them at different positions.

On a potentially related aspect, for Functions and Expressions the default f1, f2, ... names will almost surely be better served with more useful labels. I couldn't find an issue addressing it, but it might be related to this. In case there isn't a way to change the default names a custom color key might be needed and it would suffer from the same issue.

@Mattriks
Copy link
Member

Not yet. Another possible option here is to give each layer control of its own key, like this (atm this has no effect):

p = plot(
    layer([sin, cos], 0, 25, Theme(key_position=:none))
    )

@Mattriks
Copy link
Member

Yes for Functions and Expressions, currently the function names are fixed here.

@Mattriks
Copy link
Member

With Gadfly 0.6.5 the colorkey labels can now be changed directly from Guide.colorkey. Returning to the minimal example above:

p= plot(iris, Geom.point,
    x = :SepalWidth, y = :SepalLength, color = :Species, 
    Guide.colorkey(title="Not Species", labels=["setosa?", "versicolor?", "virginica?"])
    )

So the original issue here doesn't seem to apply anymore. Also there are reasons that a user might want to actually have 2 keys: Guide.colorkey and Guide.manual_color_key e.g. #1098

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

No branches or pull requests

4 participants