Re: Trying to create a clustered StackedBarChart
- To: mathgroup at smc.vnet.net
- Subject: [mg83707] Re: Trying to create a clustered StackedBarChart
- From: tomfabtastic at hotmail.com
- Date: Wed, 28 Nov 2007 05:47:46 -0500 (EST)
- References: <figu8h$fha$1@smc.vnet.net>
On Nov 27, 10:15 pm, tomfabtas... at hotmail.com wrote:
> Hello,
>
> The code below creates a stacked bar chart. However, I would like the
> columns to be clustered in pairs - so instead of reading a,2,3,4
> across the x-axis, it should read 1,2 with two columns at 1 and two
> columns at 2. I am using mathematica v6.
>
> Needs["BarCharts`"]
> StackedBarChart[{2, 2, 4, 5}, {0.5, 0.5, 0.5, 0.5},
> BarStyle -> {Yellow, Black}]
>
> Thanks,
> Tom
Have worked out how to do this, but still need help with the tick
labels on the x- axis.
barFunction[list1_, list2_, columnWidth_, columnGap_] :=
Module[{combinedList, matrixReady, outp, columnWArray, columnGArray,
columnPositions, accumColumnPositions},
columnWArray =
ConstantArray[columnWidth, Max[Length[list1], Length[list2]]];
columnGArray =
ConstantArray[columnGap, Max[Length[list1], Length[list2]]];
combinedList = Riffle[list1, list2];
columnPositions =
Prepend[Take[
Riffle[columnWArray, columnGArray], {1,
Length[combinedList] - 1}], columnWidth] ;
accumColumnPositions = Accumulate[columnPositions];
matrixReady =
Table[List[accumColumnPositions[[g]], combinedList[[g]],
0.5 ], {g, 1, Length[combinedList]}];
outp = GeneralizedBarChart[matrixReady, AxesOrigin -> {0, 0},
BarStyle -> {Black, Yellow},
Ticks -> {Table[
columnGap + (g - 1)*(columnGap + columnWidth), {g, 1,
Length[columnPositions]}], Automatic}]]
Now take two strings :
xyz = {1, 3, 5, 7, 7, 10};
abc = {2, 4, 6, 7, 7, 7};
And run function :
barFunction[xyz, abc, 0.5, 0.75]
However, I need to be able to update the x-axis labels. Instead of the
number, I would like a string at that point. Eg. {"First",
"second", ...,"Fifith", Sixth"}.
Thoughts ?
Tom