# Scatterplots for subsets of multivariate data [Updated]

Update/Re-write

There has been a lot of ambiguity over what i'm am trying to do with this question so I have decided to give it a full rewrite. I'm really sorry for the confusion. If you want to see the background please see the edit history. I hope things are clearer now..

I have some data made up into the following fashion:

datac =
{
data1 = RandomReal[1, {7, 3}],
data2 = RandomReal[1, {13, 3}],
data3 = RandomReal[1, {19, 3}],
data4 = RandomReal[1, {16, 3}],
data5 = RandomReal[1, {5, 3}]
};


data1 through data5 are subsets of a multivariate dataset with 3 independent variables. data1, for example, is composed of 7 individual data points (each with 3 variables).

If I use the following function:

Needs["StatisticalPlots"]
pairwisecol[data_, col_] :=
PairwiseScatterPlot[data,
PlotStyle -> col,
DataTicks -> True,
DataLabels -> {"x", "y", "z"}]


I can create a combined plot comparing the various subsets. E.g.

Show[{pairwisecol[data1, Red],
pairwisecol[data2, Blue],
pairwisecol[data3, Green],
pairwisecol[data4, Purple],
pairwisecol[data5, Orange]}] This curently has the major drawbacks that each subset has to be defined and have a colour explicitly assigned to it. Also, Show in this instance overlays all of the DataTicks etc, rather than just the elements from the first plot (as is normally the case with Show[{Plot1,Plot2}]).

What I'm looking for is a way to use the whole (partitioned) dataset datac to generate such a plot/diagram. i.e. something like,

Show[pairwisecol[#, Red] & /@ datac]


but, with Red being replaced by a series of colours to represent each subset (like in the plot shown).

...Alternatively, starting with a 2-level list e.g.

datap = RandomReal[1, {60, 3}];


and a definition of sublist partitions,

parts = {7, 13, 19, 16, 5};


or

partspos = {[[1;;7]], [[8;;20]], [[21;;39]], [[40;;55]], [[56;;60]]};


then defining a function something like:

pairwiseP[data_, partlist_] := ...


that would partition datap into appropriate sublists, create a series of PairwiseScatterPlot's (each with a different plot colour) and then combine them using Show.

Note that this example has n = 3 independent variables. I am looking for a method that works for 1 < n < ~20.

Can anyone suggest how to do this?

• As I see it, you have something like a 4x4 grid of triples of real numbers. What is to be plotted against what in your scatter plots? Jun 7, 2013 at 4:52
• To rephrase @Michael's query: which variables are dependent, and which ones are independent? Jun 7, 2013 at 5:23
• @0x4A4D, the actual data are part of a simplex so none are truly independent. Jun 7, 2013 at 6:22
• @MichaelE2 data[[1,ALL,1]] vs data[[1,ALL,2]]...vs data[[1,All,n]]... ...data[[2,All,1]] vs ... etc.. (so each colour will represent four points). If these data were to be plotted as a single group it would be 16 triples. So in this example i have simply partitioned the data into four subsets (list level 1) that each need to be displayed in a different colour. Does this help? Jun 7, 2013 at 6:41
• I understand data[[1,All,1]] vs data[[1,All,2]] (an "x" vs. a "y"), but not if it's joined will all n (= 3 in this case) components. Do you mean data[[1,All, i ]] vs data[[1,All, j ]], for all i < j? That would give a 4 x 3 array of plots -- would that be right? In the example plot, the label on the horizontal axis suggests that maybe two values were added -- perhaps? In theory getting the right array of plots won't be hard to do once I understand what is to be done. Jun 7, 2013 at 16:24

Problem with Ticks can be solved by fixing DataRange. I don't know what is the problem with color specification for You, I hope I have not missunderstood anything:

Needs["StatisticalPlots"]

datap = RandomReal[1, {60, 5}]; (*it works for any n*)
parts = {12, 13, 12, 13, 5}; (* remember that Total@parts == Length@datap *)
colors = {Red, Green, Orange, Blue, Black}; (*or some random, as You like*)

data = Take[datap, {1, 0} + #] & /@ (Partition[Prepend[Accumulate@parts, 0], 2, 1])

Show[
PairwiseScatterPlot[data[[ #]], DataRanges -> {{0, 1}, {0, 1}}, DataTicks -> True,
PlotStyle -> colors[[ #]], ImageSize -> 500
] & /@ Range[Length@parts]
] I suspect datap can be splitted in simpler way but I have blockout now in my head.

• This is really nice. Thanks! Jul 11, 2013 at 6:57
• @geordie there was a mistake in splitting, it's fixed now.
– Kuba
Jul 11, 2013 at 7:38

I'm still uncertain whether this is what you want. Just make an array of plots and wrap it in Grid. Fiddle with the options to get axes, dividers, etc. the way you want them.

The way I understand it, the data is really four subsets, each a group of datasets. For each group, you want to plot one group vs. another group, for each pair of groups, data[[1, All, i ]] vs data[[1, All, j ]]. I'm still unsure about the desired coloring. I've colored the plots by subset (which gives no extra information, except colors are pretty :). The question states

The individual colouring of the subsets is what i'm aiming for.

In the example plot, there are mixed colors. I can only think that the plot is an amalgamation of subsets. With my current understanding of the question, I don't how to use color to add more to each plot. I feel like I'm missing something here.

Some random data with some structure:

SeedRandom;
data1 = Map[(# + RandomReal[{-0.1, 0.1}, 3])^Range &, RandomReal[{-1, 1}, {4, 4}], {-1}];
Dimensions[data1]


Plotting functions:

colorFn[subset_] := Hue[subset/4];
plot[subset_, datasets_] := Graphics[{colorFn[subset], Point[#]},
AspectRatio -> 1/GoldenRatio, ImageSize -> 100] & /@ datasets;


Mapping the plotting functions:

Grid[
MapIndexed[plot[First@#2, Thread /@ Subsets[Transpose[#], {2}]] &, data1],
Dividers -> All] It's more interesting with 40 points instead of 4:

SeedRandom;
data1 = Map[(# + RandomReal[{-0.1, 0.1}, 3])^Range &, RandomReal[{-1, 1}, {4, 40}], {-1}];

Grid[
MapIndexed[plot[First@#2, Thread /@ Subsets[Transpose@#, {2}]] &, data1],
Dividers -> All] Just to show the data is being processed as indicated:

foo = MapIndexed[Thread /@ Subsets[Transpose@#, {2}] &, data1];
foo[[1, 1]] == Transpose@{data1[[1, All, 1]], data1[[1, All, 2]]}
foo[[1, 2]] == Transpose@{data1[[1, All, 1]], data1[[1, All, 3]]}
foo[[1, 3]] == Transpose@{data1[[1, All, 2]], data1[[1, All, 3]]}
(* etc. *)

True
True
True

• @geordie Is this on target or is it wrong? Jun 22, 2013 at 14:24
• Thanks for your patience and effort!... see my edit above. Jul 11, 2013 at 0:42