How to rotate a bar graph in Plots.jl?

1.1k views Asked by At

Executing, in the REPL, after using Plots, bar(["One","Two","Three"], [1,2,3]) works. It produces the following: Example bar graph

However, I would like to have the x axis as the y, and the y as x. I just want that same data represented with horizontal bars, y'know? How would I go about doing this?

bar([1,2,3], ["One","Two","Three"]) gets:

ERROR: MethodError: no method matching AbstractFloat(::Type{String})
Closest candidates are:
  AbstractFloat(::Bool) at float.jl:258
  AbstractFloat(::Int8) at float.jl:259
  AbstractFloat(::Int16) at float.jl:260
  ...
Stacktrace:
 [1] float(::Type{T} where T) at ./float.jl:277
 [2] _preprocess_barlike(::RecipesPipeline.DefaultsDict, ::Array{Float64,1}, ::Array{String,1}) at /home/dan/.julia/packages/Plots/GDtiZ/src/recipes.jl:509
 [3] macro expansion at /home/dan/.julia/packages/Plots/GDtiZ/src/recipes.jl:359 [inlined]
 [4] apply_recipe(::RecipesPipeline.DefaultsDict, ::Type{Val{:bar}}, ::Array{Float64,1}, ::Array{String,1}, ::Nothing) at /home/dan/.julia/packages/RecipesBase/aQmWx/src/RecipesBase.jl:281
 [5] _process_seriesrecipe(::Plots.Plot{Plots.GRBackend}, ::RecipesPipeline.DefaultsDict) at /home/dan/.julia/packages/RecipesPipeline/tkFmN/src/series_recipe.jl:48
 [6] _process_seriesrecipes!(::Plots.Plot{Plots.GRBackend}, ::Array{Dict{Symbol,Any},1}) at /home/dan/.julia/packages/RecipesPipeline/tkFmN/src/series_recipe.jl:25
 [7] recipe_pipeline!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Array{Int64,1},Array{String,1}}) at /home/dan/.julia/packages/RecipesPipeline/tkFmN/src/RecipesPipeline.jl:96
 [8] _plot!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Array{Int64,1},Array{String,1}}) at /home/dan/.julia/packages/Plots/GDtiZ/src/plot.jl:167
 [9] plot(::Array{Int64,1}, ::Vararg{Any,N} where N; kw::Base.Iterators.Pairs{Symbol,Symbol,Tuple{Symbol},NamedTuple{(:seriestype,),Tuple{Symbol}}}) at /home/dan/.julia/packages/Plots/GDtiZ/src/plot.jl:57
 [10] bar(::Array{Int64,1}, ::Vararg{Any,N} where N; kw::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/dan/.julia/packages/RecipesBase/aQmWx/src/RecipesBase.jl:402
 [11] bar(::Array{Int64,1}, ::Vararg{Any,N} where N) at /home/dan/.julia/packages/RecipesBase/aQmWx/src/RecipesBase.jl:402
 [12] top-level scope at REPL[41]:1

Executing bar(y=["One","Two","Three"], x=[1,2,3])produces this: Blank chart

I am thoroughly confused about what to try next.

1

There are 1 answers

0
Astad On BEST ANSWER
bar(["One","Two","Three"], [1,2,3], orientation=:h)

"Horizontal or vertical orientation for bar types. Values :h, :hor, :horizontal correspond to horizontal (sideways, anchored to y-axis), and :v, :vert, and :vertical correspond to vertical (the default)."[1]

REF: [1] http://docs.juliaplots.org/latest/generated/attributes_series/