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

Use categorical value orders when plotting series data #335

Open
east-winds opened this issue Sep 21, 2020 · 2 comments
Open

Use categorical value orders when plotting series data #335

east-winds opened this issue Sep 21, 2020 · 2 comments

Comments

@east-winds
Copy link

The Plots package uses the ordering of categorical values when plotting series data, changing the order of assigning colors and in the legend. Currently, VegaLite does not respect the ordering (and appears to default to alphabetical).

MWE:

using Plots, VegaLite, DataFrames

# Sample dataframe with categorical variable
df = DataFrame(name = repeat(["a","b","c"], outer = [3]),
                x = repeat([1, 2, 3], inner = [3]),
                y = rand(9))
df.name = categorical(df.name)
levels(df.name)

# Plot with the original ordering (a,b,c)
df |>
@vlplot(:line, 
    x=:x, y=:y, 
    color={"name:n"})

# Change the categorical ordering and check
levels!(df.name, reverse(levels(df.name)))
levels(df.name)

# Plot with the new ordering (unchanged) -- should be (c,b,a)
df |>
@vlplot(:line, 
    x=:x, y=:y, 
    color={"name:n"})

# For reference, Plots.plot uses the new correct ordering (c,b,a)
plot(df.x, df.y, group = df.name)

@nivupaiR
Copy link

Do we know if this feature (sorting the plots in arbitrary/based on values/non alphabetical order) support is being added to VegaLite?

@davidanthoff
Copy link
Member

Yeah, I've been thinking how we could do that... I don't really want to take a dependency on CategoricalArrays.jl, that is quite an involved package. I wish there was some lightweight interface that would allow VegaLite.jl to learn about an ordering without taking a dependency on a concrete implementation of a categorical story...

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