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

Reference nonnumeric in doctring of sorter #486

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,20 @@ end

"""
sorter(ks)
sorter(ks...)

Utility to reorder a categorical variable, as in `sorter(["low", "medium", "high"])`.
A vararg method `sorter("low", "medium", "high")` is also supported.
`ks` should include all the unique values of the categorical variable.
The order of `ks` is respected in the legend.

If you are trying to convert numbers to sorted catagorical variables, see [`nonnumeric`](@ref).

#Example
```jldoctest
julia> mapping(color = :income=>sorter("low", "medium", "high")=>"Income")
Layer(identity, nothing, Any[], {:color = :income => (AlgebraOfGraphics.Renamer{Tuple{String, String, String}, Tuple{String, String, String}}(("low", "medium", "high"), ("low", "medium", "high")) => "Income")})
```
"""
function sorter(ks::Union{AbstractArray, Tuple})
vs = map(to_string, ks)
Expand All @@ -108,6 +117,12 @@ end
nonnumeric(x)

Transform `x` into a non numeric type that is printed and sorted in the same way.

# Example
```jldoctest
julia> mapping(color = :n_children=>nonnumeric=>"Number of Children")
Layer(identity, nothing, Any[], {:color = :n_children => (AlgebraOfGraphics.nonnumeric => "Number of Children")})
```
"""
nonnumeric(x) = NonNumeric(x)

Expand Down
Loading