Sweasonable Doubt
Sweasonable Doubt

Reputation: 98

Julia Gadfly's Geom.bar fails when given horizontal orientation argument but works fine with vertical - is this a bug or am I missing something?

I am passing a "dict-of-counts" style dataframe to Gadfly to make a barplot. The output is as expected when I use the vertical orientation, but it breaks when I use horizontal. Am I misunderstanding something or should I file a quick issue report? Thanks!

using Gadfly
using DataFrames
import Cairo, Fontconfig

df = DataFrame(group = ["A", "B", "C", "D"], count = [5,10,25,15])

vertPlot = plot(df, x = :group, y = :count, Geom.bar(orientation = :vertical))
horiPlot = plot(df, x = :group, y = :count, Geom.bar(orientation = :horizontal))

plot(df, x = :group, y = :count, Geom.bar(orientation = :vertical)) |> SVG("vertical.svg") # fine
plot(df, x = :group, y = :count, Geom.bar(orientation = :horizontal)) |> SVG("horizontal.svg") # RIP

The stack trace:

[thadryan@leon Test]
~:) julia ErrorInPlotWhenHorizonatal.jl 
ERROR: LoadError: MethodError: no method matching zero(::Type{String})
Closest candidates are:
  zero(::Type{Missing}) at missing.jl:103
  zero(::Type{Pkg.Resolve.FieldValue}) at /build/julia/src/julia-1.5.4/usr/share/julia/stdlib/v1.5/Pkg/src/Resolve/fieldvalues.jl:38
  zero(::Type{Pkg.Resolve.VersionWeight}) at /build/julia/src/julia-1.5.4/usr/share/julia/stdlib/v1.5/Pkg/src/Resolve/versionweights.jl:15
  ...
Stacktrace:
 [1] apply_statistic(::Gadfly.Stat.BarStatistic, ::Dict{Symbol,Gadfly.ScaleElement}, ::Gadfly.Coord.Cartesian, ::Gadfly.Aesthetics) at /home/thadryan/.julia/packages/Gadfly/nN3lf/src/statistics.jl:239
 [2] apply_statistics(::Array{Gadfly.StatisticElement,1}, ::Dict{Symbol,Gadfly.ScaleElement}, ::Gadfly.Coord.Cartesian, ::Gadfly.Aesthetics) at /home/thadryan/.julia/packages/Gadfly/nN3lf/src/statistics.jl:33
 [3] render_prepare(::Plot) at /home/thadryan/.julia/packages/Gadfly/nN3lf/src/Gadfly.jl:680
 [4] render(::Plot) at /home/thadryan/.julia/packages/Gadfly/nN3lf/src/Gadfly.jl:740
 [5] draw at /home/thadryan/.julia/packages/Gadfly/nN3lf/src/Gadfly.jl:847 [inlined]
 [6] SVG at /home/thadryan/.julia/packages/Compose/5GmGj/src/svg.jl:286 [inlined]
 [7] |>(::Plot, ::SVG) at ./operators.jl:834
 [8] top-level scope at /home/thadryan/Workspace/Test/ErrorInPlotWhenHorizonatal.jl:12
in expression starting at /home/thadryan/Workspace/Test/ErrorInPlotWhenHorizonatal.jl:12

My instinct is that it's expecting to count something, not have a number given to it but I'm not sure I'm not familiar with the inner workings of Gadfly. Version info:

Julia: 1.5.4 (2021-03-11)

julia> Pkg.status("Gadfly")
Status `~/.julia/environments/v1.5/Project.toml`
  [c91e804a] Gadfly v1.3.2

julia> Pkg.status("DataFrames")
Status `~/.julia/environments/v1.5/Project.toml`
  [a93c6f00] DataFrames v0.22.5

julia> Pkg.status("Cairo")
Status `~/.julia/environments/v1.5/Project.toml`
  [159f3aea] Cairo v1.0.5

julia> Pkg.status("Fontconfig")
Status `~/.julia/environments/v1.5/Project.toml`
  [186bb1d3] Fontconfig v0.4.0

Upvotes: 1

Views: 97

Answers (1)

Sweasonable Doubt
Sweasonable Doubt

Reputation: 98

I didn't hear back and this seemed weird enough that I filed an issue and was directed to this issue that contained an explanation. I just had to switch what I was passing as x and y which is what I assumed this parameter was doing (Given it's a "gg"-style library I was expecting this argument to behave like coord_flip())

# change
plot(df, x = :group, y = :count, Geom.bar(orientation = :horizontal))
# to:
plot(df, x = :count, y = :group, Geom.bar(orientation = :horizontal))

It's simple but easy to miss if you're used to the way it's done in R.

Upvotes: 0

Related Questions