1
$\begingroup$

With

values = RandomInteger[{10}, 5]

this works:

    BarChart[values,
     BarOrigin -> Left,
     ChartStyle -> Orange,
     ChartElementFunction -> "GlassRectangle",
     ChartLabels -> CharacterRange["a", "e"],
     GridLines -> {{Mean@values}, None}
 ]

and delivers:

enter image description here

Now I want the line for the mean in style "Thick". Normally one uses the pair {value, style}, e.g. (from the documentation:

        Plot[Cos[x], {x, 0, 10},GridLines -> {{{Pi, Dashed}, 
        {2 Pi, Thick}}, {{-1,Orange}, -.5, .5, {1, Orange}}}]

but not with BarChart. For the following I get an error message "A line specification in the value of GridLines should be of the form: number or {number, style}."

BarChart[values,
 BarOrigin -> Left,
 ChartStyle -> Orange,
 ChartElementFunction -> "GlassRectangle",
 ChartLabels -> CharacterRange["a", "e"],
 GridLines -> {{Mean@values, Thick}, None}
 ]

Can anyone help me out and get the GridLine in Thick style?

$\endgroup$
2

2 Answers 2

1
$\begingroup$
       BarChart[values, BarOrigin -> Left, ChartStyle -> Orange, 
       ChartElementFunction -> "GlassRectangle", 
      ChartLabels -> CharacterRange["a", "e"], 
        GridLines -> {{Mean@values}, None}, 
        GridLinesStyle -> Directive[Orange, Thick]]

plot

$\endgroup$
1
$\begingroup$

You are missing a set of {} around your value/style list. The gridlines specifications should be of the form

GridLines -> {{{line1x,style1x},{line2x,style2x}}, yGridLines}

So this is what you need:

BarChart[values,
    BarOrigin -> Left, ChartStyle -> Orange, ChartElementFunction -> "GlassRectangle",
    ChartLabels -> CharacterRange["a", "e"],
    GridLines -> {{{Mean[values], Thick}}, None}
]
$\endgroup$
1
  • $\begingroup$ Thank! I've overseen this. Thank you very much. $\endgroup$
    – mgamer
    Commented May 24, 2018 at 16:17

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.