5
$\begingroup$

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

enter image description here

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.

enter image description here

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:

enter image description here

Any other options, eg using LabelingFunction?

$\endgroup$
1
  • $\begingroup$ Related: (18807) $\endgroup$
    – Mr.Wizard
    Commented Mar 7, 2017 at 6:34

1 Answer 1

7
$\begingroup$

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}]
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.