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
y
: Height of each bar.color
(optional): Group categorically by color.
Either
x
: Position of each bar.
Or
xmin
: Starting x positions for each bar.xmax
: End x positions for each bar.
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
position
: Either:stack
or:dodge
. If thecolor
aesthetic is bound this determines how bars of different colors should be arranged: stacked on top of each other, or placed side by side.orientation
: Either:vertical
(default) or:horizontal
. If:horizontal
, then the required aesthetics arey
orymin/ymax
.
Examples
plot(dataset("HistData", "ChestSizes"), x="Chest", y="Count", Geom.bar)
plot(by(dataset("datasets","HairEyeColor"),[:Eye,:Sex], d->sum(d[:Freq])),
color="Eye", y="x1", x="Sex",
Geom.bar(position=:dodge), Guide.ylabel("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)
See Scale.color_discrete_manual for more information.