Trouble plotting grouped data (VegaLite.jl)

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.

gearavg |> @vlplot(:bar, x = :Gear, y = :OverallMean, color = :Gear, encoding = {facet = {field = :Company, columns = 2}}, height = 500, width = 500) |> display
│ 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.

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

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:

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

1 Like

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.

1 Like