Function Repository Resource:

CorrelationChart

Source Notebook

Generate a chart showing pairwise correlations between values

Contributed by: Felipe Amorim

ResourceFunction["CorrelationChart"][data]

generates a chart showing pairwise correlations between values in data.

Details and Options

ResourceFunction["CorrelationChart"] shows how different variables in data correlate to each other. Plots in the lower triangle display Ellipsoid objects centered at the mean of the corresponding variable pair, diagonal plots display a Histogram of the individual variable and the upper triangle shows, by default, the numerical values of the pairwise correlation.
Ellipsoid objects are colored according to the pairwise correlation: blue indicates a positive correlation, and red indicates a negative correlation.
The input data can be a List of data points, an Association or Tabular object.
When data includes Missing values, ResourceFunction["CorrelationChart"] removes all instances containing missing elements.
Correlation values are shown in the tooltip of each plot by default.
The following options are supported:
"NumericalValues"Truedisplay of correlation values in the upper triangle of the chart
"EllipsoidQuantile"0.95confidence quantile used to create ellipsoids
ChartLabelsFalsewhether variable labels are displayed
"Colors"Truecoloring of ellipses according to correlation value
"Points"Truewhether to include the underlying scatter values
All options of GraphicsGrid are also supported.
If data is a list and ChartLabels is set to True, automatic labels will be generated. If data is an Association, its keys will be used as labels.

Examples

Basic Examples (2) 

Generate a correlation chart from a small list of values:

In[1]:=
ResourceFunction[
 "CorrelationChart"][{{1, 2, -1}, {2, 9, -8}, {-1, 3, 1}, {11, 8, 3}, {0, 1, 8}}]
Out[1]=

Generate data with 4 dimensions:

In[2]:=
n = 100;
x = RandomReal[{-1, 1}, n];
data = <|"X" -> x,
   	"Y" -> x + RandomReal[{-1, 1}, n],
   	"Z" -> x + RandomReal[{-10, 10}, n],
   	"W" -> -x + RandomReal[{-1, 1}, n]
   |>;

Show its correlation chart:

In[3]:=
ResourceFunction["CorrelationChart"][data]
Out[3]=

Scope (2) 

Get some tabular data:

In[4]:=
tab = Tabular[{{0.68, 1.59, 1.47, -0.44}, {-2.1, -2.27, 1.36, 0.83}, {-0.71, -1.27, 1.5, -0.83}, {0.48, -0.15, 0.18, 0.45}, {-1.16, -1.24, 0.66, 0}, {-0.19, 0.15, 0.15, -0.34}}]
Out[4]=

CorrelationChart also supports Tabular objects as input data:

In[5]:=
ResourceFunction["CorrelationChart"][tab]
Out[5]=

Start with some data containing Missing values:

In[6]:=
data = Tabular[{{1, 1, 2}, {10, -3, 6}, {Missing[], 8, 9}, {-1, 0, 6}}]
Out[6]=

CorrelationChart will exclude those values containing missing elements. In this case, notice how only three out of four data values are shown:

In[7]:=
ResourceFunction["CorrelationChart"][data]
Out[7]=

Options (7) 

NumericalValues (1) 

Use the "NumericalValues" option to suppress the display of correlation values in the upper triangle:

In[8]:=
ResourceFunction[
 "CorrelationChart"][{{1, 2, -1, 1}, {2, 9, -8, 5}, {-1, 3, 1, 4}, {11, 8, 3, 6}, {0, 1, 8, 7}}, "NumericalValues" -> False]
Out[8]=

EllipsoidQuantile (1) 

Set the "EllipsoidQuantile" option to different confidence quantile values used to create ellipsoids:

In[9]:=
n = 100;
x = RandomReal[{-1, 1}, n]; data = Tabular[Transpose[{x, x + RandomReal[{-1, 1}, n], x + RandomReal[{-10, 10}, n]}]]
Out[10]=
In[11]:=
ResourceFunction["CorrelationChart"][data, "EllipsoidQuantile" -> .2]
Out[11]=

ChartLabels (3) 

Use the ChartLabels option to specify labels:

In[12]:=
ResourceFunction[
 "CorrelationChart"][{{1, 2, -1}, {2, 9, -8}, {-1, 3, 1}, {11, 8, 3}, {0, 1, 8}}, ChartLabels -> {"a", "b", "c"}]
Out[12]=

If no specific label is given, setting ChartLabels to True will automatically generate synthetic labels:

In[13]:=
ResourceFunction[
 "CorrelationChart"][{{1, 2, -1}, {2, 9, -8}, {-1, 3, 1}, {11, 8, 3}, {0, 1, 8}}, ChartLabels -> True]
Out[13]=

Start with input data given as an Association with key names:

In[14]:=
n = 100;
x = RandomReal[{-1, 1}, n];
data = <|"X" -> x,
   	"Y" -> x + RandomReal[{-1, 1}, n],
   	"Z" -> x + RandomReal[{-10, 10}, n],
   	"W" -> -x + RandomReal[{-1, 1}, n]
   |>;

Setting ChartLabels to True will automatically use key names as labels:

In[15]:=
ResourceFunction["CorrelationChart"][data, ChartLabels -> True]
Out[15]=

Colors (1) 

Remove colors representing correlation values:

In[16]:=
ResourceFunction[
 "CorrelationChart"][{{1, 2, -1}, {2, 9, -8}, {-1, 3, 1}, {11, 8, 3}, {0, 1, 8}}, "Colors" -> False]
Out[16]=

Points (1) 

Remove points from ellipses:

In[17]:=
ResourceFunction[
 "CorrelationChart"][{{1, 2, -1}, {2, 9, -8}, {-1, 3, 1}, {11, 8, 3}, {0, 1, 8}}, "Points" -> False]
Out[17]=

Applications (2) 

Get area, GDP and population density data from all countries:

In[18]:=
data = EntityValue["Country", {"Area", "GDP", "PopulationDensity"}, "Tabular"]
Out[18]=

Generate a correlation chart from numerical values:

In[19]:=
ResourceFunction["CorrelationChart"][
 data[[All, {"Area", "GDP", "PopulationDensity"}]], ChartLabels -> True]
Out[19]=

Get flower data from the Fisher's iris dataset:

In[20]:=
data = DeleteColumns[ResourceData["Sample Tabular Data: Fisher Iris"],
   "Species"]
Out[20]=

Visualize their correlations:

In[21]:=
ResourceFunction["CorrelationChart"][data, ChartLabels -> True]
Out[21]=

Possible Issues (2) 

Input data must be of numeric or Quantity types:

In[22]:=
ResourceFunction[
 "CorrelationChart"][{{1, 2, 3.1}, {4, 3, 2}, {0, -3, a}}]
Out[22]=

ChartLabels must match the number of columns in the data:

In[23]:=
ResourceFunction["CorrelationChart"][{{1, 2}, {4.1, 3}, {0, -3}}, ChartLabels -> {a, b, c}]
Out[23]=

Neat Examples (2) 

Get monthly stock price data for a variety of companies:

In[24]:=
stocks = {"AAPL", "MSFT", "NOK", "GOOG", "KO", "META", "AMZN", "XOM"};
stocksData = AssociationThread[
   stocks -> (FinancialData[#, "Close", {{2022, 1, 1}, Today, "Month"}][
        "Values"] & /@ stocks)];

Visualize how they correlate:

In[25]:=
ResourceFunction["CorrelationChart"][stocksData, ChartLabels -> True]
Out[25]=

Publisher

Felipe Amorim

Version History

  • 1.0.0 – 31 October 2025

Related Resources

License Information