Skip to content

Commit

Permalink
maximums needed to account for categorical variables
Browse files Browse the repository at this point in the history
  • Loading branch information
rdboyes committed May 19, 2024
1 parent 3ed1e32 commit 78c3490
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/draw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ function Makie.SpecApi.Axis(plot::GGPlot)

# keep track of the global max and min on each axis
if haskey(given_aes, :x)
xmin = min(xmin, minimum(given_aes[:x].raw))
xmax = max(xmax, maximum(given_aes[:x].raw))
xmin = min(xmin, minimum(given_aes[:x].makie_function(given_aes[:x].raw)))
xmax = max(xmax, maximum(given_aes[:x].makie_function(given_aes[:x].raw)))
end

if haskey(given_aes, :y)
ymin = min(ymin, minimum(given_aes[:y].raw))
ymax = max(ymax, maximum(given_aes[:y].raw))
ymin = min(ymin, minimum(given_aes[:y].makie_function(given_aes[:y].raw)))
ymax = max(ymax, maximum(given_aes[:y].makie_function(given_aes[:y].raw)))
end

if length(intersect(keys(given_aes), geom.grouping_aes)) == 0 && isnothing(plot.facet_options)
Expand Down
24 changes: 13 additions & 11 deletions src/transforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,40 +83,42 @@ number_on_axis = AesTransform(number_on_axis_fn)
# categorical array handling options for String columns

function cat_inorder_fn(target::Symbol, source::Vector{Symbol}, data::DataFrame)
cat_column = data[!, source[1]]
cat_array = CategoricalArray(cat_column,
levels = unique(cat_column),
ordered = true)

label_target = target == :x ? :xticks :
target == :y ? :yticks :
nothing

return Dict{Symbol, PlottableData}(
target => PlottableData(
cat_array,
x -> levelcode.(x),
data[!, source[1]],
x -> levelcode.(CategoricalArray(x,
levels = unique(x),
ordered = true)),
label_target,
x -> (1:length(levels(x)), levels(x))
x -> (1:length(levels(CategoricalArray(x,
levels = unique(x),
ordered = true))),
levels(CategoricalArray(x,
levels = unique(x),
ordered = true)))
)
)
end

cat_inorder = AesTransform(cat_inorder_fn)

function cat_inseq_fn(target::Symbol, source::Vector{Symbol}, data::DataFrame)
cat_array = CategoricalArray(data[!, source[1]])

label_target = target == :x ? :xticks :
target == :y ? :yticks :
nothing

return Dict{Symbol, PlottableData}(
target => PlottableData(
cat_array,
x -> levelcode.(x),
data[!, source[1]],
x -> levelcode.(CategoricalArray(x)),
label_target,
x -> (1:length(levels(x)), levels(x))
x -> (1:length(levels(CategoricalArray(x))), levels(CategoricalArray(x)))
)
)
end
Expand Down

2 comments on commit 78c3490

@rdboyes
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/107184

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.6 -m "<description of version>" 78c349066c550839ed200ceb41ca2b25b52b5552
git push origin v0.7.6

Please sign in to comment.