Useful when making bar plots and have the most common level in the bottom. Also possible to remove uncommon levels and create new level called other.

size_order(x, other_count = NULL, other_level = "Övriga")

Arguments

x

Vector

other_count

How many levels should be considered as other level

other_level

What the new level should be called

Examples

table(ggplot2::diamonds$cut)
#> 
#>      Fair      Good Very Good   Premium     Ideal 
#>      1610      4906     12082     13791     21551 
in_size_order <- size_order(ggplot2::diamonds$cut)
table(in_size_order)
#> in_size_order
#>     Ideal   Premium Very Good      Good      Fair 
#>     21551     13791     12082      4906      1610 
in_size_order <- size_order(ggplot2::diamonds$cut, 2, "Others")
table(in_size_order)
#> in_size_order
#>     Ideal   Premium Very Good    Others 
#>     21551     13791     12082      6516