Hi guys!
I want to know how to use Julia to plot a bar chart like the following picture.
Specifically, each X-axis label corresponds to two or more columns.
Thank you very much!
Depends on which plotting package you want to use.
Easiest (IMHO) is AoG with a matching example in the tutorial at
1 Like
Thank you very much!
I use this package, but I still have some problems.
My data is as follows:
My code and the result are as follows:
I want to know how to modify the code to display the value of the column " Amount ", rather than the frequency of " Amountof ".
This is the example from the Makie docs:
using CairoMakie
tbl = (cat = [1, 1, 1, 2, 2, 2, 3, 3, 3],
height = 0.1:0.1:0.9,
grp = [1, 2, 3, 1, 2, 3, 1, 2, 3],
)
barplot(tbl.cat, tbl.height,
dodge = tbl.grp,
color = tbl.grp,
axis = (xticks = (1:3, ["left", "middle", "right"]),
title = "Dodged bars"),
)
Running with Jakob’s example:
julia> tbl = (cat = [1, 1, 1, 2, 2, 2, 3, 3, 3],
height = 0.1:0.1:0.9,
grp = [1, 2, 3, 1, 2, 3, 1, 2, 3],
)
(cat = [1, 1, 1, 2, 2, 2, 3, 3, 3], height = 0.1:0.1:0.9, grp = [1, 2, 3, 1, 2, 3, 1, 2, 3])
julia> plt = data(tbl) * mapping(:cat, :height) * mapping(dodge = :grp => nonnumeric) * mapping(color = :grp => nonnumeric) * visual(BarPlot)
Layer(AlgebraOfGraphics.Visual(Plot{Makie.barplot}, {}), (cat = [1, 1, 1, 2, 2, 2, 3, 3, 3], height = 0.1:0.1:0.9, grp = [1, 2, 3, 1, 2, 3, 1, 2, 3]), Any[:cat, :height], {:dodge = :grp => AlgebraOfGraphics.nonnumeric, :color = :grp => AlgebraOfGraphics.nonnumeric})
julia> fig = AlgebraOfGraphics.draw(plt)
The issue with your code is that you are calling frequency
instead of mapping(x, y)
.