I would like to plot bivariate data along with the marginal distributions. I've arranged the plots in a GraphicsGrid as below but the marginals are centered away from the bivariate plot and I wonder if there isn't a better way.
There are several related questions but none that I can find that quite work for what I'd like to do. For example, Visualization of Bivariate Distributions and Align plots with a shift.
Here is the GraphicsGrid version using PDF plots, (I'll have Histograms and a Listplot in the actual version.)
Module[{jointPDF, marg1PDF, marg2PDF, mu1, mu2, s1, s2, rho, size,
jointPlot, marg1Plot, marg2Plot, x1, x2},
mu1 = mu2 = 0;
s1 = s2 = 1;
rho = 0.4;
jointPDF = PDF[MultinormalDistribution[{mu1,mu2}, {{s1, rho}, {rho, s2}}],{x1, x2}];
marg1PDF = PDF[NormalDistribution[mu1, s1], x1];
marg2PDF = PDF[NormalDistribution[mu2, s2], x2];
size = 300;
jointPlot = ContourPlot[jointPDF, {x1, -4, 4}, {x2, -4, 4}, AspectRatio -> 1, ImageSize -> size, Contours -> 15, ContourShading -> None];
marg1Plot = Rotate[Plot[marg1PDF, {x1, -4, 4}, Axes -> False, ImageSize -> size, AspectRatio -> 1/3], -Pi/2];
marg2Plot = Rotate[Plot[marg2PDF, {x2, -4, 4}, Axes -> False, ImageSize -> size, AspectRatio -> 1/3], Pi];
GraphicsGrid[{
{jointPlot, marg1Plot},
{marg2Plot,}
}]
]
Which produces this output:
I'd like the marginals to sit more tightly on the joint distribution's plot axes but can't figure out how.
Thanks.