SeedRandom[1];
data = RandomInteger[{5, 40}, {10, 2}];
First, a helper function to pre-process input data to add metadata to be used for scaling bar widths:
preProcess = Map[Thread[# -> 1/Range[Length@#]/2] &];
and a custom ChartElementFunction
that modifies the box coordinates using attached metadata:
cEF[cedf_ : "Rectangle"] := ChartElementData[cedf][{#[[1]],
Mean[#[[2]]] + {-1, 1} #3[[1]]}, ##2] &;
We can then use BarChart
with the options BarSpacing
, BarOrigin
and the custom function cEF
as the setting for the option ChartElementFunction
BarChart[preProcess @ data,
BarSpacing -> {-1, .5},
BarOrigin -> Left,
ChartStyle -> {Lighter @ Red, Darker @ Cyan},
ChartElementFunction -> cEF[],
ChartLabels -> {ToUpperCase@Alphabet[], None},
ChartLegends ->
Placed[SwatchLegend[{"2021", "2022"},
LegendLabel -> Placed["legend:", Before], LegendLayout -> "Row"],
Above],
LabelStyle -> 14,
ImageSize -> 500]
Use ChartElementFunction -> cEF["GlassRectangle"]
to get
Use ChartElementFunction -> cEF["ArrowRectangle"]
to get
SeedRandom[1];
data2 = RandomInteger[{5, 40}, {4, 5}];
BarChart[preProcess @ data2,
BarSpacing -> {-1, .25},
BarOrigin -> Left,
ChartStyle -> "Rainbow",
ChartElementFunction -> cEFcEF[],
ChartBaseStyle -> EdgeForm[],
ChartLabels -> {{"SOUTH", "CENTRAL", "EAST", "WEST"}, None},
ChartLegends ->
Placed[SwatchLegend[{"2019", "2020", "2021", "2022", "2023"},
LegendLabel -> Placed["legend:", Before],
LegendLayout -> "Row"], Above],
LabelStyle -> 14, ImageSize -> 500]