3
$\begingroup$

I have a dataset consisting of 2 different parameters (x and y), that are evaluated for 3 different values of parameter p and within a set for p, there are, say, two groups (G1 and G2, eventually to Gn) with again three values for a parameter q. G1, G2 need to be displayed with the same ColorFunction.

How do I display this using PairedBarChart? I believe this is a nested list, but PairedBarChart only seems to take two (x and y) m-by-n (max number of dimensions = 2) matrices?

Appreciate your hints!

UPDATE: SAMPLE DATA BELOW and extra level added in description above.

Data should be interpreted as data left = x, dataright = y. In both, there is three groups p1, p2, p3 each consisting of two lists (G1 and G2), which in turn each consist of {q1,q2,q3}.

dataleft = {{{22.1801, 30.9241, 27.3873}, {30.0898, 42.7793, 38.6847}, {81.5488, 164.131, 97.6132}}, {{28.5354, 30.1192, 26.7762}, {26.7111,27.5938, 25.8865}, {72.1467,91.9632, 53.7431}}};
dataright (*here identical to left, just for the idea*) = {{{22.1801, 30.9241, 27.3873},{30.0898, 42.7793, 38.6847}, {81.5488,164.131, 97.6132}}, {{28.5354, 30.1192, 26.7762}, {26.7111, 27.5938, 25.8865}, {72.1467, 91.9632, 53.7431}}};
$\endgroup$
  • 1
    $\begingroup$ You should provide a sample of the dataset. $\endgroup$ – Öskå Aug 5 '14 at 16:08
2
$\begingroup$

Given the nested structure of your data you should consider ChartLayout -> Stacked:

dataleft = {{{22.1801, 30.9241, 27.3873}, {30.0898, 42.7793, 
     38.6847}, {81.5488, 164.131, 97.6132}}, {{28.5354, 30.1192, 
     26.7762}, {26.7111, 27.5938, 25.8865}, {72.1467, 91.9632, 
     53.7431}}};

dataright = {{{22.1801, 30.9241, 27.3873}, {30.0898, 42.7793, 
    38.6847}, {81.5488, 164.131, 97.6132}}, {{28.5354, 30.1192, 
    26.7762}, {26.7111, 27.5938, 25.8865}, {72.1467, 91.9632, 
    53.7431}}};

s11 = dataleft[[1]];
s12 = dataleft[[2]];
s21 = dataright[[1]];
s22 = dataright[[2]];

labels = Reverse@Range@Length@s1;

Left-Right

s1 = Flatten[Transpose[{s11, s12}], 1];
s2 = Flatten[Transpose[{s21, s22}], 1] - 10;

PairedBarChart[s1, s2,
 AxesLabel -> "Nr.",
 ChartLabels -> {Placed[{"Left", "Right"}, Above], Placed[labels, "CenterAxis"], None},
 ChartLayout -> "Stacked",
 ChartLegends -> SwatchLegend[{"A", "B", "C"}]]

enter image description here

First-Second

p1 = Flatten[Transpose[{s11, s21 - 10}], 1];
p2 = Flatten[Transpose[{s12, s22 - 10}], 1];

PairedBarChart[p1, p2,
 AxesLabel -> "Nr.",
 ChartLabels -> {Placed[{"First", "Second"}, Above], Placed[labels, "CenterAxis"], None},
 ChartLayout -> "Stacked",
 ChartLegends -> SwatchLegend[{"A", "B", "C"}]]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks, but it's not what I'm looking for. I need to be able to read the values, so non-stacking is preferred. Moreover, I'd like to have e.g. Nr. 1 and 2 labeled p1, and then another label '1' (and '2') for the triplet (which is now stacked, but should be separated). Any ideas? $\endgroup$ – user18798 Aug 5 '14 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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