# Support for CategoricalValue in StatsPlots

**URL:** https://discourse.julialang.org/t/support-for-categoricalvalue-in-statsplots/47523
**Category:** Visualization
**Tags:** statsplots
**Created:** [September 30, 2020, 5:05am UTC](https://discourse.julialang.org/t/support-for-categoricalvalue-in-statsplots/47523 "2020-09-30T05:05:57Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![lyonsquark](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lyonsquark/32/4483_2.png) [@lyonsquark](https://discourse.julialang.org/u/lyonsquark)
#### Post date: [November 23, 2020, 4:25am UTC](https://discourse.julialang.org/t/support-for-categoricalvalue-in-statsplots/47523/4 "2020-11-23T04:25:00Z")

</div>

I had totally forgotten that I had asked a similar question over two years ago. See [Ordering the y-axis values in a dotplot](https://discourse.julialang.org/t/ordering-the-y-axis-values-in-a-dotplot/10642) . Here is a workaround…

Assuming the `:VoicePart` is the categorical array, then you can do…

```julia
cticks(ctg::CategoricalArray) = (1:length(levels(ctg)), levels(ctg))
df singers violin(levelcode.(:VoicePart),:Height, xticks=cticks(:VoicePart), side=:right, marker=(0.2, :blue, stroke(0)), label="Scala")

```

A bit ugly, but it works. Basically, the x value is the integer code for the the level of that entry and then the `xticks` is a translation from that code to the string level description.

Would be nice if `CategoricalArrays` just worked for plotting. There’s an open issue about this at [https://github.com/JuliaData/CategoricalArrays.jl/issues/256](https://github.com/JuliaData/CategoricalArrays.jl/issues/256) .

---

_[View the full topic](https://discourse.julialang.org/t/support-for-categoricalvalue-in-statsplots/47523)._
