11

This barchart was tricky to style, and I had to resort to the legacy BarCharts`package. Any ideas how to omit the labels from the bottom edge? Ideally I'd also like separator ticks between the column pairs.

data = {{-2.8, -5.8, -7.4, -9.2}, {-3.7, -6.8, -8.9, -11.8}};

colour1 = RGBColor[82/255, 85/255, 255/255];
colour2 = RGBColor[132/255, 178/255, 255/255];

Quiet[Needs["BarCharts`"]]

BarChart[data, Frame -> True, AxesOrigin -> {0, 0}, 
 PlotRange -> {{0.525, 4.825}, {-14, 0}},
 BarLabels -> {"March", "June", "September", "December"},
 BarGroupSpacing -> 0.3, BarSpacing -> 0, 
 BarStyle -> {colour1, colour2},
 BaseStyle -> {10, FontFamily -> "Verdana"}, AspectRatio -> 0.4, 
 ImageSize -> 350]

enter image description here

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
Chris Degnen
  • 30,927
  • 2
  • 54
  • 108

3 Answers3

12

There is no need to use the deprecated BarCharts` package — you can create this chart using only built-in functions:

BarChart[Transpose@data, 
    ChartStyle -> {colour1, colour2}, 
    ChartLabels -> {Placed[{"March", "June", "September", "December"}, Above], None}, 
    Frame -> True, FrameTicks -> {False, True}, 
    BaseStyle -> {10, FontFamily -> "Verdana"}, BarSpacing -> {0, 0.3}, 
    AspectRatio -> 0.4, ImageSize -> 350, PlotRangePadding -> {0.4, 0.1}
]

enter image description here

rm -rf
  • 88,781
  • 21
  • 293
  • 472
9

Just some fun seeing how well I can dial it in by eye:

BarChart[Thread @ data,
 ChartStyle -> {colour1, colour2}, 
 ChartLabels -> {Placed[{"March", "June", "September", "December"}, Above], None},
 Frame -> True,
 FrameTicks -> {False, True}, 
 BaseStyle -> {10, FontFamily -> "Verdana"},
 BarSpacing -> {0, 0.8}, 
 PlotRangePadding -> {0.8, {2.2, 0}},
 AspectRatio -> 0.4, 
 ImageSize -> 350
]

recreation

original

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • That's great, thanks. And with FrameTicks freed up I can add the column separator ticks too, ie: BarChart[Thread@data, ChartStyle -> {colour1, colour2}, ChartLabels -> {Placed[{"March", "June", "September", "December"}, Above], None}, Frame -> True, FrameTicks -> {{True, True}, {False, Map[{#, Null} &, (Range[Length[First@data] - 1]*(2 + 0.8)) - 0.8/2]}}, BaseStyle -> {10, FontFamily -> "Verdana"}, BarSpacing -> {0, 0.8}, PlotRangePadding -> {0.8, {2.2, 0}}, AspectRatio -> 0.4, ImageSize -> 350] – Chris Degnen May 30 '12 at 10:30
  • @Chris Thanks for the Accept. – Mr.Wizard May 30 '12 at 10:37
  • I'm curious — did you feel this was significantly different from my answer? I guess I had just forgotten his ImageSize and AspectRatio... – rm -rf May 30 '12 at 13:55
  • R.M I didn't intend my answer as complete (and I voted for yours); I just wanted to see how visually close I could get (I didn't actually look at his code for the purpose). FWIW I used BarSpacing, PlotRangePadding. I was hesitant to edit your answer with my messing about. I think your question implies that I should have. Would you have preferred that? Would you still prefer that? – Mr.Wizard May 30 '12 at 17:43
  • @Mr.Wizard It isn't about the vote or rep... As I browse through the site, I come across answers from new users like this (and another on the same Q and a few more that I can't seem to find right now), which are fundamentally the same as an existing answer. I try to tell them to keep things tidy and not post small modifications as a separate answers (sometimes these are inevitable in instant replies like in list-manipulation, where they probably weren't aware of others). Usually they understand (except for that chap on the progress bar Q)... – rm -rf May 31 '12 at 01:42
  • (contd...) So it sorta weakens my case when regular users often do this. I understand the urge to play around and sometimes, small changes add up to different results, and posting that's fine. But here I felt that the only thing missing was a minor PlotRangePadding (I did have BarSpacings) and I didn't pay heed to that because the OP mainly wanted to know how to remove the labels from the bottom... If you felt editing was too much, you could've commented. Either way, I don't care about points or accepts... Just that others shouldn't point to this to justify their incremental answers. – rm -rf May 31 '12 at 01:46
  • Just to clarify — I'm not asking you to delete or transfer the accept. It was just an observation, that's all. – rm -rf May 31 '12 at 01:53
  • @R.M Duly noted. I didn't post it as a comment because the code was too long and I specifically wanted to juxtapose the images. For future reference, you would have been OK with it if I had edited that into your answer, correct? – Mr.Wizard May 31 '12 at 03:38
  • @Mr.Wizard I wouldn't have minded it :) – rm -rf May 31 '12 at 03:54
  • 1
    @R.M AAaahh! Hypno-Toad! – Mr.Wizard May 31 '12 at 03:59
8

Like the other answers, I also suggest using the new BarChart. If you decide to stick with the BarCharts` package anyway, you can post process the ticks, like this:

Suppose the graphics object is named fig, then

{th, tv} = FrameTicks /. Options[fig, FrameTicks]

(* ==>
 {{{1.175, "March", 0}, {2.175, "June", 0}, 
  {3.175, "September", 0}, {4.175, "December", 0}}, Automatic}
)*

Show[fig, FrameTicks -> {{tv, tv}, {None, th}}]

Mathematica graphics

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263