Skip to content

Commit

Permalink
Update draw.jl
Browse files Browse the repository at this point in the history
adds fct_inorder arg to ggplot
  • Loading branch information
rdboyes committed Feb 28, 2024
1 parent 17251eb commit 1594ed7
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/draw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ function draw_ggplot(plot::GGPlot)
end

if eltype(plot_data[!, aes_dict[a]]) <: Union{AbstractString, AbstractChar}
cat_array = CategoricalArray(plot_data[!, aes_dict[a]])
if haskey(plot.axis_options, "fct_inorder")
cat_column = plot_data[!, aes_dict[req_aes]]
cat_array = CategoricalArray(cat_column, levels = unique(cat_column), ordered = true)
else
cat_array = CategoricalArray(plot_data[!, aes_dict[req_aes]])
end
column_data = levelcode.(cat_array)
labels = levels(cat_array)
args_dict[a * "ticks"] = (1:length(labels), labels)
Expand Down Expand Up @@ -102,7 +107,12 @@ function draw_ggplot(plot::GGPlot)

for req_aes in required_aes
if eltype(plot_data[!, aes_dict[req_aes]]) <: Union{AbstractString, AbstractChar}
cat_array = CategoricalArray(plot_data[!, aes_dict[req_aes]])
if haskey(plot.axis_options, "fct_inorder")
cat_column = plot_data[!, aes_dict[req_aes]]
cat_array = CategoricalArray(cat_column, levels = unique(cat_column), ordered = true)
else
cat_array = CategoricalArray(plot_data[!, aes_dict[req_aes]])
end
column_data = levelcode.(cat_array)
labels = levels(cat_array)
axis_options[Symbol(req_aes * "ticks")] = (1:length(labels), labels)
Expand All @@ -119,6 +129,12 @@ function draw_ggplot(plot::GGPlot)
push!(plot_list, Makie.PlotSpec(geom.visual, args...; kwargs...))
end

# remove options from args_dict that are not meant for Makie

if haskey(plot.axis_options, "fct_inorder")
delete!(plot.axis_options, "fct_inorder")
end

# rename and correct types on all axis options

for (arg, value) in plot.axis_options
Expand Down

0 comments on commit 1594ed7

Please sign in to comment.