Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Further to my previous question, is there a concise way - amenable to automated setting in a package so that it can be accessed globally - to eliminate some legend item that would otherwise show? For example, in this example, I'd like to only show the orange rectangle and text "Preliminary estimates".

enter image description here

I tried a couple of replacement rules, by analogy with belisarius’s answer for reversing stacked bar chart legends, such as the example below, but it doesn’t seem to make any difference.

BarChart[RandomVariate[NormalDistribution[0, 0.6], 40], 
 ChartStyle -> Join[ConstantArray[Green, {39}], {Orange}], 
 ChartLegends -> 
 Placed[Join[ConstantArray[None, {39}], {"Preliminary estimates"}], 
 Bottom]] /. Pane[Row[x_]] :> Pane[Row[Last[x]]]
share|improve this question
1  
You could build a GUI that allows you to select which items are shown in a legend via checkboxes but the solutions below are more straight forward for specific cases. –  Mike Honeychurch Jun 4 '12 at 0:38
    
@MikeHoneychurch well, in principle I could, but in practice, that won't be me :) –  Verbeia Jun 4 '12 at 1:33
    
...as per this video: ibnhconsulting.blogspot.com.au/2011/11/… –  Mike Honeychurch Jun 4 '12 at 2:06

3 Answers 3

up vote 3 down vote accepted

The reason your code doesn't work is because the legends are typeset using a Row with two arguments (where the second argument is a separator which should be placed between the entries in the legend) but you're matching to a Row with only one argument. You could instead do something like

BarChart[RandomVariate[NormalDistribution[0, 0.6], 40], 
 ChartStyle -> Join[ConstantArray[Green, {39}], {Orange}], 
 ChartLegends -> 
 Placed[Join[ConstantArray[None, {39}], {"Preliminary estimates"}], 
 Bottom]] /. Pane[Row[x_, ___]] :> Pane[Last[x]]

Mathematica graphics

Edit

Another way to selectively label entries in the BarChart is to do something like this

BarChart[RandomVariate[NormalDistribution[0, 0.6], 40], 
 ChartStyle -> Join[ConstantArray[Green, {39}], {Orange}], 
 ChartLegends -> 
  Join[ConstantArray[
    None, {39}], {Placed["Preliminary estimates", Bottom]}]]
share|improve this answer
    
I just realised that some months ago I had come up with the second option you posted here and forgotten about it! It's definitely the cleanest option for my purpose. –  Verbeia Jun 4 '12 at 0:00

Use MapAt to apply the Legended and Style wrappers directly to the last item in the dataset:

data = RandomVariate[NormalDistribution[0, 0.6], 40];

data = MapAt[Legended[Style[#, Orange], "Preliminary estimate"] &, data, -1];

BarChart[data, ChartStyle -> Green, LegendAppearance -> "Row"]

enter image description here

share|improve this answer

Of course, this got a lot easier in version 9:

BarChart[RandomVariate[NormalDistribution[0, 0.6], 40], 
 ChartStyle -> Join[ConstantArray[Green, {39}], {Orange}], 
 ChartLegends -> Placed[SwatchLegend[{Orange}, {"Estimate"}], Bottom]]

enter image description here

share|improve this answer
    
Definitely simpler. –  rcollyer May 10 '13 at 13:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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