This test BarChart is generated by the code that follows it:

data = Table[RandomInteger[{1, 10}], {3}, {4}];
BarChart[MapThread[Labeled[#1, #2, Above] &, {data, {1, 2, 3}}],
ChartLayout -> "Stacked",
ChartStyle ->
Reverse@{Lighter@Blue, Blue, Darker@Blue, Darker@Darker@Blue},
ChartLabels -> {{"a", "b", "c"}, None},
Frame -> {False, True, False, False},
FrameLabel -> {"x axis", "y axis"},
BaseStyle -> {FontFamily -> "Helvetica", FontSize -> 14}]
Since only a y-axis component of Frame is rendered: Frame -> {False, True, False, False} the "x axis" label of FrameLabel -> {"x axis", "y axis"} is omitted - and that's consistent with documentation.
Is it possible to display "x axis" at the location it would be if the bottom component of the Frame were there and preserving the set BaseStyle values (eg Font, FontSize)?
This can be done using Inset but positioning is ad-hoc and it does not preserve BaseStyle values.
Wrapping Labeled around Barchart doesn't correctly center the text and moreover does not use the BaseStyle values, as the following screenshot shows. Here for comparison the bottom component of Frame is True - and note the disastrous clash of graphical elements.

Finally, using the bottom Frame component: Frame -> {True, True, False, False} but without ticks: FrameTicks -> {None, Automatic, None, None} results in an ugly double axis and overlap in labels:

Any other options, eg using LabelingFunction?
Answer
You can remove the overlaid ticks by using FrameTicksStyle to set them to Transparent and remove the doubled edge by setting PlotRangePadding to None, like so:
BarChart[MapThread[Labeled[#1, #2, Above] &, {data, {1, 2, 3}}],
ChartLayout -> "Stacked",
ChartStyle ->
Reverse@{Lighter@Blue, Blue, Darker@Blue, Darker@Darker@Blue},
ChartLabels -> {{"a", "b", "c"}, None},
Frame -> {True, True, False, False},
FrameTicksStyle -> {Automatic, Transparent},
PlotRangePadding -> None, FrameLabel -> {"x axis", "y axis"},
BaseStyle -> {FontFamily -> "Helvetica", FontSize -> 14}]
Or you could explicitly set the FrameTicks to something invisible but that takes up the same vertical spacing you want, like so:
BarChart[MapThread[Labeled[#1, #2, Above] &, {data, {1, 2, 3}}],
ChartLayout -> "Stacked",
ChartStyle ->
Reverse@{Lighter@Blue, Blue, Darker@Blue, Darker@Darker@Blue},
ChartLabels -> {{"a", "b", "c"}, None},
Frame -> {True, True, False, False},
FrameTicks -> {{Automatic, Automatic}, {{{1, ""}}, None}},
PlotRangePadding -> None, FrameLabel -> {"x axis", "y axis"},
BaseStyle -> {FontFamily -> "Helvetica", FontSize -> 14}]
Comments
Post a Comment