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

legend improvements #106

Open
1 of 4 tasks
cnrrobertson opened this issue May 24, 2024 · 3 comments
Open
1 of 4 tasks

legend improvements #106

cnrrobertson opened this issue May 24, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@cnrrobertson
Copy link
Contributor

cnrrobertson commented May 24, 2024

Describe how it works in R's ggplot2

  • Legends work with categorical variables, Example: ggplot(diamonds, aes(x=x,y=y,color=color)) + geom_point()
  • Multiple legends
    • For multiple aes specs. Example: ggplot(diamonds, @aes(x=Depth, y=Price)) + geom_point(@aes(color=Carat)) + geom_point(@aes(color=Table))
    • Generate a legend for aes with multiple features (such as both size and color), Example: ggplot(diamonds, aes(x=x,y=y,color=color, size=carat)) + geom_point()
@cnrrobertson cnrrobertson added the enhancement New feature or request label May 24, 2024
@rdboyes
Copy link
Member

rdboyes commented May 26, 2024

Can you elaborate on the first point? I think legends already work with categorical variables, e.g.

ggplot(penguins, @aes(x=bill_length_mm,y=bill_depth_mm,color=island)) + geom_point()

image

@cnrrobertson
Copy link
Contributor Author

You're right! I didn't realize. But I think I've stumbled on a bug - it doesn't work when the DataFrame column for color is a CategoricalVector (apparently most/all? datasets from RDatasets.jl have categorical columns stored in that format). But I think this an upstream issue in Makie:

ERROR: MethodError: no method matching to_color(::CategoricalValue{String, UInt8})

Closest candidates are:
  to_color(::Makie.Palette)
   @ Makie ~/.julia/packages/Makie/iRM0c/src/conversions.jl:845
  to_color(::Symbol)
   @ Makie ~/.julia/packages/Makie/iRM0c/src/conversions.jl:854
  to_color(::Makie.Scene, ::Any, ::Makie.Cycled)
   @ Makie ~/.julia/packages/Makie/iRM0c/src/makielayout/blocks/axis.jl:695
  ...

You can recreate with

using CategoricalArrays
penguins.island = categorical(penguins.island)
ggplot(penguins, @aes(x=bill_length_mm, y=bill_depth_mm, size=island)) + geom_point()

Alternatively, we could try to convert those columns to strings when plotting?

@rdboyes
Copy link
Member

rdboyes commented May 28, 2024

It's strange - I actually convert the Strings to CategoricalVectors under the hood already. Should be an easy fix I think, I'm sure I'm just missing a check somewhere

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

No branches or pull requests

2 participants