1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| Options[plotGrid] = {ImagePadding -> 40, "KeepAR" -> False}; plotGrid[l_List, w_, h_, opts : OptionsPattern[]] := Module[{nx, ny, sidePadding = OptionValue[plotGrid, ImagePadding], topPadding = 0, widths, heights, dimensions, positions, frameOptions = FilterRules[{opts}, FilterRules[Options[Graphics], Except[{ImagePadding, Frame, FrameTicks}]]]}, {ny, nx} = Dimensions[l]; widths = If[OptionValue["KeepAR"], Module[{arfunc, arlist, tot}, arfunc[img_] := Module[{dims}, dims = ImageDimensions[ Show[img, ImagePadding -> {{0, 0}, {0, 0}}]]; N@dims[[1]]/dims[[2]]]; arlist = arfunc /@ l[[1]]; tot = Total[arlist]; Table[ arlist[[n]] (w - 2 sidePadding)/tot, {n, nx}]], (w - 2 sidePadding)/nx Table[1, {nx}]]; widths[[1]] = widths[[1]] + sidePadding; widths[[-1]] = widths[[-1]] + sidePadding; heights = If[OptionValue["KeepAR"], Module[{arfunc, arlist, tot}, arfunc[img_] := Module[{dims}, dims = ImageDimensions[ Show[img, ImagePadding -> {{0, 0}, {0, 0}}]]; N@dims[[2]]/dims[[1]]]; arlist = arfunc /@ l[[All, 1]]; tot = Total[arlist]; Table[ arlist[[-n]] (h - 2 sidePadding)/tot, {n, ny}]], (h - 2 sidePadding)/ny Table[1, {ny}]]; heights[[1]] = heights[[1]] + sidePadding; heights[[-1]] = heights[[-1]] + sidePadding; positions = Transpose@ Partition[ Tuples[Prepend[Accumulate[Most[#]], 0] & /@ {widths, heights}], ny]; Graphics[ Table[Inset[ Show[l[[ny - j + 1, i]], ImagePadding -> {{If[i == 1, sidePadding, 0], If[i == nx, sidePadding, 0]}, {If[j == 1, sidePadding, 0], If[j == ny, sidePadding, topPadding]}}, AspectRatio -> Full], positions[[j, i]], {Left, Bottom}, {widths[[i]], heights[[j]]}], {i, 1, nx}, {j, 1, ny}], PlotRange -> {{0, w}, {0, h}}, ImageSize -> {w, h}, Evaluate@Apply[Sequence, frameOptions]]];
data5 = {RandomVariate[NormalDistribution[50, 10], 100], RandomVariate[NormalDistribution[20, 1], 100], RandomVariate[NormalDistribution[80, 5], 100]};
hist = Show[ Plot[140 PDF[SmoothKernelDistribution[#], x] & /@ data5, {x, 0, 100}, Evaluated -> True, PlotStyle -> {Red, Green, Blue}, Frame -> True, PlotRange -> {{0, 100}, All}], Histogram[data5, ChartStyle -> {Red, Green, Blue}]]; bxchrt = BoxWhiskerChart[data5, BarOrigin -> Left, AspectRatio -> 1/3, ChartStyle -> {Red, Green, Blue}, PlotRange -> {First@Charting`get2DPlotRange@hist, All}, PlotRangePadding -> None]; plotGrid[{{hist}, {bxchrt}}, 500, 400, "KeepAR" -> True]
|