Function Repository Resource:

MarginalPlot

Source Notebook

Plot 2D data together with visualizations of the marginal distributions

Contributed by: Jon McLoone

ResourceFunction["MarginalPlot"][data]

produces a ListPlot of 2D data together with visualizations of the marginal distributions.

ResourceFunction["MarginalPlot"][data,binspec]

uses the bin specification binspec.

Details and Options

ResourceFunction["MarginalPlot"] supports options of Graphics with the following additions:
“MarginalChartType"Histogramthe chart type used to display the marginal distributions
“MarginalChartScale"0.3proportion of space provided for charts of marginal distributions
“MarginalChartOptions"{}list of any options supported by the visualization used for the marginal distributions
Supported values for "MarginalChartType" are Histogram, DistributionChart and BoxWhiskerChart.
The binspec uses the same specification as the built-in function Histogram
The binspec is ignored if the "MarginalChartType" is not Histogram

Examples

Basic Examples (3) 

See the marginal distributions of 2D data together with the data:

In[1]:=
ResourceFunction["MarginalPlot"][
 RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500]]
Out[1]=

Display the marginal distributions using DistributionChart:

In[2]:=
ResourceFunction["MarginalPlot"][
 RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500], "MarginalChartType" -> DistributionChart]
Out[2]=

Display the marginal distributions using BoxWhiskerChart:

In[3]:=
ResourceFunction["MarginalPlot"][
 RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 1000], "MarginalChartType" -> BoxWhiskerChart]
Out[3]=

Scope (3) 

Specify the number of bins for Histogram marginal plots:

In[4]:=
data = RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500];
ResourceFunction["MarginalPlot"][data, 40]
Out[5]=

Specify the bin widths:

In[6]:=
ResourceFunction["MarginalPlot"][data, {1}]
Out[6]=

Mix different types of visualization for the different marginal distributions:

In[7]:=
data = RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500];
ResourceFunction["MarginalPlot"][data, "MarginalChartType" -> { Histogram, DistributionChart}]
Out[8]=
In[9]:=
data = RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500];
ResourceFunction["MarginalPlot"][data, "MarginalChartType" -> { DistributionChart, BoxWhiskerChart}]
Out[10]=

Options (3) 

The type of chart used to display the marginal distribution is controlled with "MarginalChartType". Choices available are Histogram, DistributionChart and BoxWhiskerChart:

In[11]:=
ResourceFunction["MarginalPlot"][
 RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500], "MarginalChartType" -> DistributionChart]
Out[11]=

A list of two different values can be given for "MarginalChartType":

In[12]:=
ResourceFunction["MarginalPlot"][
 RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500], "MarginalChartType" -> {Histogram, DistributionChart}]
Out[12]=

The proportion of the plot space occupied by the Histogram elements is controlled by "MarginalChartScale":

In[13]:=
data = RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500];
ResourceFunction["MarginalPlot"][data, "MarginalChartScale" -> 0.05]
Out[14]=

Create larger histograms:

In[15]:=
ResourceFunction["MarginalPlot"][data, "MarginalChartScale" -> 0.5]
Out[15]=

Standard Graphics options are supported:

In[16]:=
data = RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500];
ResourceFunction["MarginalPlot"][data, AspectRatio -> 1.3]
Out[17]=

All standard options for the visualizations used for the marginal distributions are supported and must be passed in using the option "MarginalChartOptions":

In[18]:=
ResourceFunction["MarginalPlot"][
 RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500],
 "MarginalChartOptions" -> {ChartElementFunction -> "GradientScaleRectangle"}]
Out[18]=

Likewise, options for DistributionChart and BoxWhiskerChart are supported:

In[19]:=
ResourceFunction["MarginalPlot"][
 RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500],
 "MarginalChartType" -> DistributionChart, "MarginalChartOptions" -> {ChartElementFunction -> "HistogramDensity"}]
Out[19]=
In[20]:=
ResourceFunction["MarginalPlot"][
 RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500],
 "MarginalChartType" -> DistributionChart, "MarginalChartOptions" -> {ChartElementFunction -> "PointDensity"}]
Out[20]=

Publisher

Jon McLoone

Version History

  • 1.1.0 – 22 February 2023
  • 1.0.0 – 01 July 2022

Related Resources

License Information