1
$\begingroup$

I have two BarChart:

BarChart[{0.35, 1.27, 0.33, 0.83, 0.7, 0.25, 0, 0.004, 0.16},ChartLabels -> {"Voc","Pyth", "Idio", "Inf", "Pap", "Math","H-La", "H-Math", "H-Poe"}, ChartStyle -> "DarkRainbow", Frame -> True]

BarChart[{N[0.3], N[81/90], N[30/45], N[210/90], N[645/600],N[15/120], N[0/60],N[30/150], N[75/90]}, ChartLabels -> {"Voc", "Pyth", "Idio", "Inf", "Pap", "Math","H-La", "H-Math", "H-Poe"}, ChartStyle -> "DarkRainbow", Frame -> True]

My main questions are:

How can I draw a horizontal line crossing the unity (1.0) in a BarChart.

Also, How can I combine two charts so that two charts overlies on each other? However, the cost of this may be to change the color of the graphs, which is not a problem.

I try:

{{0.35, 1.27, 0.33, 0.83, 0.7, 0.25, 0, 0.004, 0.16},{N[0.3], N[81/90], N[30/45], N[210/90], N[645/600],N[15/120], N[0/60],N[30/150], N[75/90]}}

and

{{0.35,N[0.3]}, {1.27,N[81/90]}, {0.33,N[30/45]},...{}};

But they are not the desired goal.

$\endgroup$
2
  • 2
    $\begingroup$ Try BarChart[..., , Epilog -> {Black, Thick, Line[{{0.5, 1}, {9.5, 1}}]}] where 9.5 is becaues there are 9 data points. $\endgroup$ Mar 3 at 14:48
  • $\begingroup$ very good comments $\endgroup$
    – monfneg
    Mar 3 at 14:59

2 Answers 2

1
$\begingroup$
Clear["Global`*"]
label1x = {"Voc", "Pyth", "Idio", "Inf", "Pap", "Math", "H-La", 
  "H-Math", "H-Poe"};
col = Rest@(ColorData["DarkRainbow"][#] & /@ 
    Subdivide[1, Length@label1x]);
list1 = {0.35, 1.27, 0.33, 0.83, 0.7, 0.25, 0, 0.004, 0.16};
list2 = {N[0.3], N[81/90], N[30/45], N[210/90], N[645/600], N[15/120],
    N[0/60], N[30/150], N[75/90]};
data = Transpose[{list1, list2, label1x, col}]

Dimensions /@ {list1, list2, label1x, col}

BarChart[Labeled[Transpose@{Style[#1, #4], Style[#2, #4]}, #3, 
    Below] & @@@ data
 , Frame -> {{True, True}, {True, True}}
 , AspectRatio -> 4/10
 , FrameStyle -> Thickness[.001]
 , LabelStyle -> Directive[Black, Bold, Medium]
 , BarSpacing -> {0.1, 0.4}
 , FrameTicks -> {{Automatic, None}, {None, None}}
 , ImageSize -> 600
 , GridLines -> None
 , ChartLegends -> 
  Placed[SwatchLegend[col, label1x, 
    LegendLayout -> {"Column", 1}], {0.8, 0.51}]
 , Epilog -> {Black, Dashed, Line[{{0, 1}, {2.4*Length@list1, 1}}]}
 ]

enter image description here

Or you may prefer the following version that highlights the two separate datasets (since the ChartLabels are already there):

BarChart[Labeled[Transpose@{#1, #2}, #3, Below] & @@@ data
 , Frame -> {{True, True}, {True, True}}
 , AspectRatio -> 4/10
 , FrameStyle -> Thickness[.001]
 , ChartStyle -> {Red, Blue}
 , LabelStyle -> Directive[Black, Bold, Medium]
 , BarSpacing -> {0.1, 0.4}
 , FrameTicks -> {{Automatic, None}, {None, None}}
 , ImageSize -> 600
 , GridLines -> None
 , ChartLegends -> Placed[{"ds1", "ds2"}, {0.9, 0.7}]
 , Epilog -> {Black, Dashed, Line[{{0, 1}, {2.4*Length@list1, 1}}]}
 ]

enter image description here

$\endgroup$
1
  • $\begingroup$ Very delicious answer.... It is the exact issue I was searching $\endgroup$
    – monfneg
    Mar 4 at 0:50
1
$\begingroup$

To get a horizontal line, you may use "Epilog:"

BarChart[{0.35, 1.27, 0.33, 0.83, 0.7, 0.25, 0, 0.004, 0.16}, 
 ChartLabels -> {"Voc", "Pyth", "Idio", "Inf", "Pap", "Math", "H-La", 
   "H-Math", "H-Poe"}, ChartStyle -> "DarkRainbow", Frame -> True, 
 Epilog -> Line[{{0.2, 1}, {10, 1}}]]

enter image description here

And to get an overly of 2 charts:

d = {{0.35, 1.27, 0.33, 0.83, 0.7, 0.25, 0, 0.004, 0.16}, {N[0.3], 
     N[81/90], N[30/45], N[210/90], N[645/600], N[15/120], N[0/60], 
     N[30/150], N[75/90]}} // Transpose;
BarChart[d, ChartLayout -> "Stacked"]

enter image description here

$\endgroup$

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