# Trouble plotting grouped data (VegaLite.jl)

**URL:** https://discourse.julialang.org/t/trouble-plotting-grouped-data-vegalite-jl/42874
**Category:** Visualization
**Created:** [July 10, 2020, 9:34pm UTC](https://discourse.julialang.org/t/trouble-plotting-grouped-data-vegalite-jl/42874 "2020-07-10T21:34:26Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Chris\_Anderson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chris_anderson/32/9465_2.png) [@Chris\_Anderson](https://discourse.julialang.org/u/Chris_Anderson)
#### Post date: [July 10, 2020, 9:34pm UTC](https://discourse.julialang.org/t/trouble-plotting-grouped-data-vegalite-jl/42874/1 "2020-07-10T21:34:26Z")

</div>

I’m having a lot of trouble plotting this df the way I would like. What I hope to produce is seven plots (faceted by company), each plot having gear on the x axis and Overall mean on the y axis. Each company does not necessarily have each gear possibility, there are different combinations.  
When I attempt to plot this I just get an empty white box with labeled axes.  
Here is the plot code and df. The df is called `gearavg`.

```julia
gearavg |> @vlplot(:bar, x = :Gear, y = :OverallMean, color = :Gear, encoding = {facet = {field = :Company, columns = 2}}, height = 500, width = 500) |> display

```

```julia
│ Row │ Company │ Gear │ OverallMean │
│ │ Any │ Any │ Any │
├─────┼────────────────────────┼──────────────────────┼─────────────┤
│ 1 │ Davey │ Hitch-Climber Pulley │ 81.8056 │
│ 2 │ Davey │ Other │ 80.473 │
│ 3 │ Davey │ Split Tail │ 78.4773 │      
│ 4 │ Davey │ Taut Line │ 79.3547 │
│ 5 │ Mario's │ Hitch-Climber Pulley │ 80.5731 │
│ 6 │ Mario's │ Other │ 79.6182 │
│ 7 │ Mario's │ Split Tail │ 70.0 │
│ 8 │ Mario's │ Taut Line │ 82.4842 │
│ 9 │ Arbor Works │ Hitch-Climber Pulley │ 82.0848 │
│ 10 │ Arbor Works │ Other │ 79.4654 │
│ 11 │ Arbor Works │ SRT │ 100.0 │
│ 12 │ Arbor Works │ Split Tail │ 90.0 │
│ 13 │ Arbor Works │ Taut Line │ 80.0 │
│ 14 │ MLU Willhelm │ Hitch-Climber Pulley │ 74.9731 │
│ 15 │ MLU Willhelm │ Other │ 78.3824 │
│ 16 │ MLU Willhelm │ SRT │ 92.5 │
│ 17 │ MLU Willhelm │ Split Tail │ 73.9 │
│ 18 │ MLU Willhelm │ Taut Line │ 74.625 │
│ 19 │ Asplundh │ Hitch-Climber Pulley │ 76.3833 │
│ 20 │ Asplundh │ Other │ 80.2429 │
│ 21 │ Asplundh │ Split Tail │ 77.5727 │
│ 22 │ Asplundh │ Taut Line │ 78.8714 │
│ 23 │ Wright Tree Service │ Hitch-Climber Pulley │ 85.0 │
│ 24 │ Wright Tree Service │ Other │ 80.0 │
│ 25 │ Wright Tree Service │ Split Tail │ 81.5476 │
│ 26 │ Mowbray’s Tree Service │ Hitch-Climber Pulley │ 85.635 │
│ 27 │ Mowbray’s Tree Service │ Other │ 82.7 │
│ 28 │ Mowbray’s Tree Service │ SRT │ 88.8333 │
│ 29 │ Mowbray’s Tree Service │ Split Tail │ 82.0 │

```

This is giving me a lot of trouble. I’ve tried many ways of grouping the data and nothing seems to work. I would be eternally grateful for any tips or solutions.

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [July 11, 2020, 3:37pm UTC](https://discourse.julialang.org/t/trouble-plotting-grouped-data-vegalite-jl/42874/2 "2020-07-11T15:37:24Z")

</div>

The problem is the type “Any” of your categorial columns :Company and :Gear.  
Please try

```julia
gearavg[!,:Company] = convert(Array{String,1},gearavg[!,:Company])
gearavg[!,:Gear] = convert(Array{String,1},gearavg[!,:Gear])
gearavg |> @vlplot(:bar, x = :Gear, y = :OverallMean, color = :Gear, encoding = {facet = {field = :Company, columns = 2}}, height = 500, width = 500)

```

The ` |> display` at the end is not needed.

For future questions you should provide Copy&Paste code. This makes it much easier to help. Your DataFrame isn’t copy&paste code, so it needs some coding to reproduce your issue. See:

```julia
using DataFrames, VegaLite

companies=["Davey","Mario's","Arbor Works","MLU Willhelm","Asplundh","Wright Tree Service","Mowbray’s Tree Service"]
gears=["Hitch-Climber Pulley","Other","Split Tail","Taut Line","SRT"]

drop=trues(35)
drop[[4,6,15,23,30] ] .= false

gearavg= DataFrame( Company= convert(Array{Any,1},[x[2] for x in vec(collect(Iterators.product(gears,companies))) ][drop]) )
gearavg[!,:Gear]= convert(Array{Any,1},[x[1] for x in vec(collect(Iterators.product(gears,companies))) ][drop])
gearavg[!,:OverallMean]= convert(Array{Any,1},(100 .* rand(Float64,size(gearavg)[1])))

gearavg |> @vlplot(:bar, x = :Gear, y = :OverallMean, color = :Gear, encoding = {facet = {field = :Company, columns = 2}}, height = 50, width = 50)

gearavg[!,:Company] = convert(Array{String,1},gearavg[!,:Company])
gearavg[!,:Gear] = convert(Array{String,1},gearavg[!,:Gear])

gearavg |> @vlplot(:bar, x = :Gear, y = :OverallMean, color = :Gear, encoding = {facet = {field = :Company, columns = 2}}, height = 50, width = 50)

```

This is just hacked together to make your issue appear in my REPL.  
Therefore consider

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

### Author: ![Chris\_Anderson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chris_anderson/32/9465_2.png) [@Chris\_Anderson](https://discourse.julialang.org/u/Chris_Anderson)
#### Post date: [July 14, 2020, 5:14pm UTC](https://discourse.julialang.org/t/trouble-plotting-grouped-data-vegalite-jl/42874/3 "2020-07-14T17:14:04Z")

</div>

I was able to change the column types and it worked. Thank you for your input and your guidance on how to better ask questions.
