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