# Seaborn like countplot

**URL:** <https://discourse.julialang.org/t/seaborn-like-countplot/25133>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [June 10, 2019, 11:39pm UTC](https://discourse.julialang.org/t/seaborn-like-countplot/25133 "2019-06-10T23:39:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GdMacmillan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdmacmillan/32/8839_2.png) [@GdMacmillan](https://discourse.julialang.org/u/GdMacmillan)\
**Post date:** [June 10, 2019, 11:39pm UTC](https://discourse.julialang.org/t/seaborn-like-countplot/25133/1 "2019-06-10T23:39:24Z")

</div>

I was looking for a recipe for the type of plot used in Seaborn to group categorical data. The Countplot, shown below from python is what I want.

 ![02%20PM](https://global.discourse-cdn.com/julialang/original/3X/5/2/525a639514b7ed77811e402c0642199937a04e2a.png)  
Is this implemented in julia or easy to do so?

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [June 11, 2019, 12:54am UTC](https://discourse.julialang.org/t/seaborn-like-countplot/25133/2 "2019-06-11T00:54:47Z")

</div>

With [VegaLite.jl](https://github.com/queryverse/VegaLite.jl), something like this?

```julia
using DataFrames, VegaLite

df = DataFrame(is_bad=rand(Bool, 10_000))

df |> @vlplot(:bar, x="is_bad:n", y="count()")

```

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [June 11, 2019, 6:50am UTC](https://discourse.julialang.org/t/seaborn-like-countplot/25133/3 "2019-06-11T06:50:15Z")

</div>

This is not se easy to do in Plots, though the recipe would be easy to add.

```julia
using StatsBase, Plots
d = countmap(rand(0:1, 10_000))
bar(collect(keys(d)), collect(values(d)))

```

We should add a recipe for `Dict` that obviated the bottom call.

---

<div class="post-metadata">

**Author:** ![GdMacmillan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdmacmillan/32/8839_2.png) [@GdMacmillan](https://discourse.julialang.org/u/GdMacmillan)\
**Post date:** [June 12, 2019, 10:21pm UTC](https://discourse.julialang.org/t/seaborn-like-countplot/25133/4 "2019-06-12T22:21:15Z")

</div>

The best I could do using juliadb table t (i added a column called ‘ones’):  
`a = groupby(sum, pushcol(t, :ones, ones(1:n_examples)), :is_bad, select=:ones)`

Table with 2 rows, 2 columns:  
is\_bad sum  
──────────────  
0 8705.0  
1 1295.0

`@df a bar!(:sum)`

 ![42%20PM](https://global.discourse-cdn.com/julialang/original/3X/7/a/7af827be792c90a9924b116ac7cc070e4b7342ac.png)

Any suggestions?
