Geom.bar

Geom.bar

Draw bar plots. This geometry works on pre-summarized data such as counts. To draw histograms from a series of observations, add Stat.histogram to the plot, or use the convenient geometry Geom.histogram.

Aesthetics

Either

Or

If x is given, a bar will be drawn at each x value, specifying both xmin and xmax allows bars of variable width to be drawn.

Arguments

Examples

plot(dataset("HistData", "ChestSizes"), x="Chest", y="Count", Geom.bar)
Chest 30 35 40 45 50 0 500 1000 1500 Count
plot(by(dataset("datasets","HairEyeColor"),[:Eye,:Sex], d->sum(d[:Freq])),
    color="Eye", y="x1", x="Sex",
    Geom.bar(position=:dodge), Guide.ylabel("Freq"))
Sex Male Female Brown Blue Hazel Green Eye 0 50 100 150 Freq
D = by(dataset("datasets","HairEyeColor"), [:Eye,:Sex], d->sum(d[:Freq]))
 rename!(D, :x1, :Frequency)
# Is there a hazel color?
palette=["brown","blue","tan","green"]

pa= plot(D, x=:Sex, y=:Frequency, color=:Eye, Geom.bar(position=:stack),
    Scale.color_discrete_manual(palette...)
)
pb= plot(D, x=:Sex, y=:Frequency, color=:Eye, Geom.bar(position=:stack),
    Scale.color_discrete_manual(palette[4:-1:1]..., order=[4,3,2,1])
)
hstack(pa, pb)
Sex Male Female Green Hazel Blue Brown Eye 0 100 200 300 400 Frequency Sex Male Female Brown Blue Hazel Green Eye 0 100 200 300 400 Frequency

See Scale.color_discrete_manual for more information.