Julia Gadfly 的 Geom.bar 在给出水平方向参数时失败,但在垂直方向上工作正常 - 这是错误还是我遗漏了什么?

问题描述

我正在将“dict-of-counts”样式数据框传递给 Gadfly 以制作条形图。当我使用垂直方向时输出符合预期,但当我使用水平方向时它会中断。我是误解了什么还是应该提交快速问题报告?谢谢!

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,Geom.bar(orientation = :horizontal))

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

堆栈跟踪:

[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},::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

我的直觉是它期待计算一些东西,没有给它一个数字,但我不确定我不熟悉 Gadfly 的内部工作原理。 版本信息:

朱莉娅: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

解决方法

我没有收到回复,这似乎很奇怪,以至于我提交了 issue 并被定向到包含解释的 this issue。我只需要切换我作为 xy 传递的内容,这就是我假设这个参数在做什么(鉴于它是一个“gg”风格的库,我希望这个参数表现得像 {{ 1}})

coord_flip()

如果您习惯了在 R 中的处理方式,这很简单但很容易错过。