TidierOrg / TidierPlots.jl

Tidier data visualization in Julia, modeled after the ggplot2 R package.
MIT License
222 stars 8 forks source link

legend improvements #106

Open cnrrobertson opened 5 months ago

cnrrobertson commented 5 months ago

Describe how it works in R's ggplot2

rdboyes commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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

rdboyes commented 1 month ago

This is fixed in 0.8.0! Multiple legends are still a work in progress though