0
$\begingroup$

I have two questions about the following graph:

1) How can I make the x-axis labels to be just "aaa" and "bbb" and not stacked on each other?

2) How can I make the legend to be in one line? Why LegendAppearance -> "Row" doesn't work?

  BarChart[{Range[4], Range[4]}, 
 ChartLabels -> {Placed[Rotate[#, 90 Degree] & /@ {"aaa", "bbb"}, 
    Below]}, ChartLayout -> "Stacked", 
 ChartLegends -> 
  Placed[{"First \n Bracket", "Second \n Bracket", "Third \n Bracket",
     "Top \n Bracket"}, Below], LegendAppearance -> "Row"]
$\endgroup$
  • $\begingroup$ Not quite sure what you want. Compare BarChart[{1, 2, 3}, ChartLabels -> Placed[{"a", "b", "c"}, Top]] and BarChart[{1, 2, 3}, ChartLabels -> Placed[Rotate[#, 90 Degree] & /@ {"a", "b", "c"}, Top]]. Is this similar to what you want ? $\endgroup$ – Lotus Sep 27 '17 at 4:44
  • $\begingroup$ None of these. I want {"a","b","c"} to be shown at the bottom of the bars below the x-axis, not above the axis. And also to make them vertical. $\endgroup$ – Hossein Sep 27 '17 at 5:07
  • $\begingroup$ Something like this then ? BarChart[{Range[3], Range[3]}, ChartLabels -> {Placed[ Rotate[#, 90 Degree] & /@ {"aaa", "bbb", "ccc"}, Below]}] $\endgroup$ – Lotus Sep 27 '17 at 10:38
  • $\begingroup$ Thanks Lotus! I think I am getting close to what I want, just I don't know why the labels are also getting stacked when I use the stacked style: BarChart[{Range[4], Range[4]}, ChartLabels -> {Placed[Rotate[#, 90 Degree] & /@ {"aaa", "bbb"}, Below]}, ChartLayout -> "Stacked", ChartLegends -> Placed[{"First \n Bracket", "Second \n Bracket", "Third \n Bracket", "Top \n Bracket"}, Below]] $\endgroup$ – Hossein Sep 27 '17 at 17:42
1
$\begingroup$

(This is basically a repeat of @kglr's deleted answer.)

You can add a second argument of None to the ChartLabels option to suppress labeling individual stacks, and you can use an explicit SwatchLegend with a non-default LegendLayout option as follows:

BarChart[
    {Range[4], Range[4]},
    ChartLabels->{Placed[Rotate[#, 90 Degree]& /@ {"aaa","bbb"},Below], None},
    ChartLayout->"Stacked",
    ChartLegends->Placed[
        SwatchLegend[
            Automatic,
            {"First \n Bracket","Second \n Bracket","Third \n Bracket","Top \n Bracket"},
            LegendLayout->{"Row",1}
        ],
        Below
    ]
]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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