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

Cannot plot CategoricalValue Variables #117

Closed
drizk1 opened this issue Sep 11, 2024 · 2 comments
Closed

Cannot plot CategoricalValue Variables #117

drizk1 opened this issue Sep 11, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@drizk1
Copy link
Member

drizk1 commented Sep 11, 2024

Describe the bug
When trying to plot a a categorical CategoricalValue{String, UInt32} (or any CategoricalValue) variable the following error occurs

ERROR: ArgumentError: cannot compare a `CategoricalValue` to value `v` of type `Float64`: wrap `v` using `CategoricalValue(v, catvalue)` or `CategoricalValue(v, catarray)` first
Stacktrace:
  [1] isless(x::CategoricalValue{String, UInt32}, y::Float64)
    @ CategoricalArrays ~/.julia/packages/CategoricalArrays/0yLZN/src/value.jl:153
  [2] min(x::Float64, y::CategoricalValue{String, UInt32})
    @ Base ./operators.jl:490
  [3] (::Makie.var"#1100#1106"{Makie.var"#1100#1101#1107"{Symbol}})(plot::TidierPlots.GGPlot)
    @ TidierPlots ~/.julia/packages/TidierPlots/LtsvY/src/draw.jl:92
  [4] draw_ggplot(plot::TidierPlots.GGPlot)
    @ TidierPlots ~/.julia/packages/TidierPlots/LtsvY/src/draw.jl:226
  [5] (::TidierPlots.var"#211#212"{TidierPlots.GGPlot})()
    @ TidierPlots ~/.julia/packages/TidierPlots/LtsvY/src/show.jl:76
  [6] (::Makie.var"#315#316"{@Kwargs{}, TidierPlots.var"#211#212"{TidierPlots.GGPlot}, MakieCore.Attributes})()
    @ Makie ~/.julia/packages/Makie/8h0bl/src/theming.jl:232
  [7] lock(f::Makie.var"#315#316"{@Kwargs{}, TidierPlots.var"#211#212"{TidierPlots.GGPlot}, MakieCore.Attributes}, l::ReentrantLock)

but it will work as a string

To Reproduce

using TidierCats, TidierPlots
using Random
Random.seed!(10)
categories = ["High", "Medium", "Low", "Zilch"];
random_indices = rand(1:length(categories), 57);
df = DataFrame(
    ID = 1:57,
    CatVar = categorical([categories[i] for i in random_indices], levels = categories));

ggplot(df) + 
 geom_bar(@aes(x = CatVar))

Expected behavior

Ideally it would graph the graph.

Screenshots

df.CatVar = string.(df.CatVar)

ggplot(df) + 
 geom_bar(@aes(x = CatVar))

download

Additional context

Status `~/.julia/environments/v1.10/Project.toml`
  [337ecbd1] TidierPlots v0.7.8 `https://github.com/TidierOrg/TidierPlots.jl#main
@drizk1 drizk1 added the bug Something isn't working label Sep 11, 2024
@drizk1
Copy link
Member Author

drizk1 commented Sep 14, 2024

@rdboyes I took a shot at solving this.. but came up short. I wonder if it's related to the dates issue?

@rdboyes
Copy link
Member

rdboyes commented Sep 17, 2024

Fixed by #118 !

@rdboyes rdboyes closed this as completed Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants