[Date Index]
[Thread Index]
[Author Index]
Re: plot of "marginal distributions" of scatter plot
*To*: mathgroup at smc.vnet.net
*Subject*: [mg74127] Re: plot of "marginal distributions" of scatter plot
*From*: "er" <erwann.rogard at gmail.com>
*Date*: Mon, 12 Mar 2007 04:35:43 -0500 (EST)
*References*: <esu6u0$rs8$1@smc.vnet.net>
Hi,
i'm also quite interested in marginal and conditional plots. it would
be nice if you gave all the code for your example. below is my own
attempt at a conditional plot with Figure 6.9 of "Elements of
statistical learning" by Hastie et al 2001 as ideal template.
basically it creates graphs within rectangles for the ranges of the
variables conditioned on and displays them on top of the plot for the
unconditioned variables. you could probably do something along those
lines for a marginal plot. however, the graphs produced by the code
below fall short of publication quality. in particular the top panels
are shorter in width than the main panel. any suggestion to properly
arrange the rectangles would be appreciated.
e.
(*---code---*)
Options[condRange] = {Frame -> True,
FrameTicks -> {None, None, Automatic, None}};
condRange[min_, max_, condMin_, condMax_, {gr___}, opts___?
OptionQ] :=
Graphics[{GrayLevel[1], Rectangle[{min, 0}, {max, 0.25*(max -
min)}],
GrayLevel[0.6], Rectangle[{condMin, 0}, {condMax, 0.25*(max -
min)}],
Sequence @@ {gr}}, opts, Options[condRange]];
condRanges[all : {{_, _, _, _, _List, ___?OptionQ} ..}, opts___?
OptionQ] :=
Module[{}, GraphicsArray[List /@ Apply[condRange, all, {1}],
opts]];
condRangesMain[main_, ar1_, condRngs_, ar2_, opts___?OptionQ] :=
Module[{},
Graphics[{Rectangle[{0, 0}, {1, ar1}, main],
Rectangle[{0, ar1}, {1, ar1 + ar2}, condRngs]},
AspectRatio -> ar1 + ar2, opts]];
isIn[{All, ints___}][{arg_, args___}] := isIn[{ints}][{args}];
isIn[{int_, ints___}][{arg_, args___}] /; IntervalMemberQ[int,
arg] :=
isIn[{ints}][{args}];
isIn[{int_, ints___}][{arg_, args___}] = False;
isIn[{}][{}] = True;
dataSel[data_, ints : {_Interval | All}] :=
Module[{}, Select[data, isIn[ints, #] &]];
Options[Main] = {Frame -> False, Axes -> {True, True},
DisplayFunction -> Identity};
dataCondScatt::qt =
"warning: interval `1` not contained in `2` for dimesion `3`";
dataCondScatt[data_, ints : {(Interval[{_, _}] | All) ..}, labels_,
ar1_,
ar2_, Plot -> plot_, probs_?VectorQ] :=
Module[{sel, main, pos, qt, cR, cRar, posAll},
pos = Position[ints, _Interval];
posAll = Position[ints, All];
sel = Select[data, isIn[ints]];
main =
plot[sel[[All, Flatten[Position[ints, All]]]], AspectRatio ->
ar1,
AxesLabel -> Flatten[Extract[labels, posAll]],
Options[Main]];
qt =
MapThread[
Quantile[#1, {#2/2, 1 - #2/2}] &, {Extract[data, pos],
probs}];
MapThread[
If[Not[IntervalMemberQ[#1, #2]],
Message[dataCondScatt::qt, #2, #1, #2]] &, {Interval /@
qt,
Extract[ints, pos], pos}];
txt[{m_, M_}, Interval[{l_, u_}]] := {m + (M - m)/2, 0.125*(M -
m)};
cR = MapThread[(Print[#1, #2, txt[#1, #2]];
condRange[Sequence @@ #1,
Sequence @@ (#2[[1]]), {GrayLevel[0],
Text[#3, txt[#1, #2], TextStyle -> {FontWeight ->
"Bold"}]},
AspectRatio -> ar2, Frame -> False,
Axes -> {True, False}]) &, {qt, Extract[ints, pos],
Extract[labels, pos]}];
cRar = GraphicsArray[List /@ cR, AspectRatio ->
Length[pos]*ar2];
condRangesMain[main, ar1, cRar, Length[pos]*ar2]];
multDataCondScatt[data_, ints : {(_Interval | All) ..} .., labels_,
ar1_,
ar2_, Plot -> plot_] :=
dataCondScatt[data, #, labels, ar1, ar2, Plot -> plot] & /@ ints;
(*--Example--*)
rnd = Array[Random[] &, {5000, 4}];
dataCondScatt[rnd, {Interval[{0.5, 0.6}], All, All,
Interval[{0.5, 0.6}]}, {"a", "b", "c", "d"}, 0.4, 0.1,
Plot -> ListPlot, {0, 0}]
% // Show[#, DisplayFunction -> $DisplayFunction] &
On Mar 10, 7:05 am, Claus <claus.hasla... at web.de> wrote:
> Hi,
> I'd like to plot the "marginal distributions" of a scatterplot just on
> the sides of the scatterplot.
> I'd like to have something similar to this (the "Axis bar plot"), but
> with mathematica:http://www.cl.cam.ac.uk/~sjm217/projects/graphics/
>
> so far I've come up with this:
> Show[GraphicsArray[{{Histgr1, ScatPlot1}, {, Histgr2}}]]
> which admittedly is lame. However I am new to mathematica, so I wonder
> if anybody has better suggestions.
>
> Thanks,
> Claus
Prev by Date:
**Re: logical/set theoretic programming**
Next by Date:
**How do I write tabular output?**
Previous by thread:
**Re: PN junction Simulation with Mathematica**
Next by thread:
**How do I write tabular output?**
| |