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

Geom.bar - Colorkey does not adhere to the order specified in Scale.x_discrete #811

Open
dstoeckel opened this issue Mar 2, 2016 · 2 comments
Labels

Comments

@dstoeckel
Copy link

To group related classes together in a Geom.bar plot I used Scale.x_discrete.
The (simplified) code reads as follows:

df = DataFrame(value=[5,1,6,3], class=["a", "b", "c", "d"]);
plot(
    df, x=:class, y=:value, color=:class,
    Geom.bar, Scale.x_discrete(levels=["b","a","c","d"])
);

gsea1

The problem here is, that the colors and the position of the levels in the colorkey are not chosen consistently with the order specified in levels. This becomes a problem when multiple plots are generated where new classes are added. In this case I would like to keep a consistent ordering and coloring scheme between the plots by appending the new class to the levels. Currently, however, the classnames seem to be sorted lexicographically which will result in shift of all colors.

@tlnagy tlnagy added the bug label Sep 9, 2016
@Mattriks
Copy link
Member

In Gadfly (and ggplot2), each aesthetic (e.g. x,y,color) has its own scale, and the scales operate independently.
In Gadfly, the levels argument controls the order for each scale:

using Gadfly, RDatasets
mtcars = dataset("datasets","mtcars")
p = plot(mtcars, x=:Cyl, color=:Cyl, Geom.histogram,
  Scale.x_discrete(levels=[8,6,4]), Scale.color_discrete(levels=[8,6,4]) )    

scale_discrete

@Mattriks
Copy link
Member

In ggplot2, the limits argument controls the order:

require("ggplot2")
ggplot(mtcars, aes(x=factor(cyl), fill=factor(cyl))) + geom_bar() + 
 scale_x_discrete(limits=c("8","6","4")) + scale_fill_hue(limits=c("8","6","4"))

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

3 participants