diff --git a/src/helpers.jl b/src/helpers.jl index 0f06bb6d3..a59bf438d 100644 --- a/src/helpers.jl +++ b/src/helpers.jl @@ -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) @@ -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)