1
$\begingroup$

Simple task: I would like to place two bar charts in a row and have an indicator horizontal line going above the two bar charts.

What I did:

bar1 = BarChart[{100, 75, 100}, ChartLayout -> "Stacked", 
   ChartStyle -> {Blue, Black, Blue}, Frame -> False, Axes -> False, 
   PlotLabel -> "bar1"];
bar2 = BarChart[{100, 38, 15, 38, 85}, ChartLayout -> "Stacked", 
   ChartStyle -> {Blue, Black, White, Black, Blue}, Frame -> False, 
   Axes -> False, PlotLabel -> "bar2"];
indicator = 
  Plot[-65 + 100, {x, 0, 4}, PlotStyle -> Red, 
   PlotLegends -> ToString[65]];

To combine the plots, I tried:

Show[Row[bar1, bar2], indicator]

but the result:

enter image description here

HELP ! The colors need to be the same.

This is how it should look like in the end: enter image description here

$\endgroup$
  • $\begingroup$ No, I misunderstood what you wanted. Actually, I don't know what you want. Is there some example figure out there that you could link to so that we can see what you want? $\endgroup$ – march Aug 4 '16 at 15:25
  • $\begingroup$ @march, I hope this helps. $\endgroup$ – henry Aug 4 '16 at 15:37
  • $\begingroup$ Row requires the objects to be put in a list in the first argument, like in Row[{obj1, obj2, ...}]. You miss the curly braces in your code $\endgroup$ – glS Aug 4 '16 at 15:39
  • $\begingroup$ Something like Overlay[{GraphicsRow[{bar1, bar2}],indicator}] but I am not sure where exactly you want that line to pass. $\endgroup$ – e.doroskevic Aug 4 '16 at 15:46
  • $\begingroup$ @march add answer? $\endgroup$ – Feyre Aug 4 '16 at 16:20
5
$\begingroup$

Use Epilog and GraphicsRow. Something like

GraphicsRow[{bar1, bar2},
  Spacings -> -20,
  Epilog -> {Red, Thickness[0.02], Line[{{0, -180}, {750, -180}}]}
 ]

and you can change the coordinates {{0, -180}, {750, -180}} of the Line by trial and error to get what you want (that's how I usually do it). The result is

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.