# Represent a correlation matrix via a graph

Posted 1 month ago
508 Views
|
8 Replies
|
4 Total Likes
|
 I have a simple (maybe mistake!) question. Is it possible to present a correlation matrix via a graph? For example: data1 = {11.22, 12.29, 12.97, 14.15, 17.33, 17.60, 16.62, 14.43, 13.62, 11.01}; data2 = {12.29, 12.97, 14.15, 17.33, 17.60, 16.625, 14.43, 13.62, 11.01, 9.25}; data3 = {12.97, 14.15, 17.33, 17.60, 16.625, 14.43, 13.62, 11.016, 9.25, 9.48}; Apply[Correlation, Tuples[{data1, data2, data3}, 2] // Partition[#, 3, 3] &, {2}] // MatrixPlot[#, ColorFunction -> "DeepSeaColors", PlotLegends -> Automatic] & Thank you for your help.
8 Replies
Sort By:
Posted 1 month ago
 If you allow for edges to have custom weights, then I'm pretty sure that yes you can represent a correlation matrix with a directed graph. However, if you just label the edges with their weights, it may be challenging to visualize. It would be easy to include/omit edges if the correlation matrix was binary. Changing the thickness or opacity of the edges with their weights would be the best way to visualize a correlation matrix as a graph in my opinion.
Posted 1 month ago
 Along the lines that Joseph suggested corr = Apply[Correlation, Tuples[{data1, data2, data3}, 2] // Partition[#, 3, 3] &, {2}] WeightedAdjacencyGraph[corr, DirectedEdges -> True, EdgeStyle -> {DirectedEdge[i_, j_] :> AbsoluteThickness[corr[[i, j]]]}, PlotTheme -> "Scientific"] 
Posted 1 month ago
 Wow!Thank you so much, man. For more understanding, is it possible to show correlation values on the figure?
Posted 1 month ago
 As Sam said, this can be easily found in the documentation. rounded = Round[corr, .01] WeightedAdjacencyGraph[rounded, DirectedEdges -> True, EdgeStyle -> {DirectedEdge[i_, j_] :> AbsoluteThickness[rounded[[i, j]]]}, EdgeLabels -> "EdgeWeight", PlotTheme -> "Scientific"] 
Posted 1 month ago
 Hi Rohit,That is great. I noticed that recently in the scientific papers, researchers show the correlation between some lists through a graph like the following figure. I thought it may be interesting for you. Best RegardsMohammad
Posted 1 month ago
 Thank you, Joseph.May I ask you to do for the example data? Is the result understandable?