{"id":1996,"date":"2017-07-14T18:15:45","date_gmt":"2017-07-14T17:15:45","guid":{"rendered":"http:\/\/pcool.dyndns.org:8080\/statsbook\/?page_id=1996"},"modified":"2025-07-01T20:31:20","modified_gmt":"2025-07-01T19:31:20","slug":"hierarchical-edge-bundling-plot","status":"publish","type":"page","link":"https:\/\/pcool.dyndns.org\/index.php\/hierarchical-edge-bundling-plot\/","title":{"rendered":"Hierarchical Edge Bundling Plot"},"content":{"rendered":"\n<p>A hierarchical edge bundling plot can be used to show <a href=\"https:\/\/pcool.dyndns.org\/index.php\/correlation-coefficient\/\" data-type=\"page\" data-id=\"823\">correlations<\/a>, similar to a <a href=\"https:\/\/pcool.dyndns.org\/index.php\/correlation-plot\/\" data-type=\"page\" data-id=\"1998\">correlation plot<\/a>. Typically, it is used for larger data sets. To create the plot, <a href=\"https:\/\/pcool.dyndns.org\/index.php\/packages\/\" data-type=\"page\" data-id=\"22\">install<\/a>&nbsp;the edgebundleR package<sup class='sup-ref-note' id='note-zotero-ref-p1996-r1-o1'><a class='sup-ref-note' href='#zotero-ref-p1996-r1'>1<\/a><\/sup><\/p>\n\n\n\n<p>Base R contains a data frame \u2018mtcars\u2019 with information about different cars. To show the first six observations&nbsp;(head) of the data frame and obtain further information about the variables in the data frame:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f00c2b\" class=\"has-inline-color\">head(mtcars)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0c16f0\" class=\"has-inline-color\">\n                   mpg cyl disp  hp drat    wt  qsec vs am gear carb\nMazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4\nMazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4\nDatsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1\nHornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1\nHornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2\nValiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f00c1b\" class=\"has-inline-color\">str(mtcars)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0c16f0\" class=\"has-inline-color\">\n'data.frame':\t32 obs. of  11 variables:\n $ mpg : num  21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...\n $ cyl : num  6 6 4 6 8 6 8 4 4 6 ...\n $ disp: num  160 160 108 258 360 ...\n $ hp  : num  110 110 93 110 175 105 245 62 95 123 ...\n $ drat: num  3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...\n $ wt  : num  2.62 2.88 2.32 3.21 3.44 ...\n $ qsec: num  16.5 17 18.6 19.4 17 ...\n $ vs  : num  0 0 1 1 0 1 0 1 1 1 ...\n $ am  : num  1 1 1 0 0 0 0 0 0 0 ...\n $ gear: num  4 4 4 3 3 3 3 4 4 4 ...\n $ carb: num  4 4 1 1 2 1 4 2 2 4 ...<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>First, create a correlation matrix that contains the correlation coefficients between the different variables:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>corr_matrix &lt;- cor(mtcars)<\/em><\/span><\/code><\/pre>\n\n\n\n<p>Convert the matrix to an igraph object needed for edgebundleR:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f5021b\" class=\"has-inline-color\">library(igraph)\ncorr_matrix &lt;- graph_from_adjacency_matrix(corr_matrix, mode = \"undirected\", weighted = TRUE, diag = FALSE)<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>Next create the plot using the edgebundleR package<sup class='sup-ref-note' id='note-zotero-ref-p1996-r2-o1'><a class='sup-ref-note' href='#zotero-ref-p1996-r2'>2<\/a><\/sup>:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">library(edgebundleR)<\/span><\/em>\n<em><span style=\"color: #ff0000;\">edgebundle(corr_matrix)<\/span><\/em><\/code><\/pre>\n\n\n\n<p>The plot should now appear in your web browser. The folder that contains the files to create the plot is shown in the address bar of your browser. This folder will be deleted when you close R, so leave R open. Go to the folder shown in the address bar of your browser and copy the folder with all its subfolders and paste it to your web server. Set up a link and the plot should be available on your server:<\/p>\n\n\n\n<p><a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/weblinks\/edgebundleT0.5\" target=\"_blank\" rel=\"noreferrer noopener\">Default Plot<\/a><\/p>\n\n\n\n<p>By hovering over the nodes, the associations become visible.<\/p>\n\n\n\n<p>By default, the &#8216;tension&#8217; of the blue lines between the nodes is 0.5, but can be set to any value between 0 and 1. With the tension set to 1:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">edgebundle(corr_matrix, tension = 1)<\/span><\/em><\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/weblinks\/edgebundleT1\" target=\"_blank\" rel=\"noreferrer noopener\">Plot with Tension = 1<\/a><\/p>\n\n\n\n<p>It is also possible to specify the &#8216;cutoff&#8217;. To show all associations were the <a href=\"https:\/\/pcool.dyndns.org\/index.php\/correlation-coefficient\/\" data-type=\"page\" data-id=\"823\">correlation coefficient<\/a> is larger than 0.7 (70%):<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">edgebundle(corr_matrix, cutoff = 0.7)<\/span><\/em><\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/weblinks\/edgebundleC0.7\" target=\"_blank\" rel=\"noreferrer noopener\">Plot with Cutoff 70%<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A hierarchical edge bundling plot can be used to show correlations, similar to a correlation plot. Typically, it is used for larger data sets. To create the plot, install&nbsp;the edgebundleR package Base R contains a data frame \u2018mtcars\u2019 with information about different cars. To show the first six observations&nbsp;(head) of the data frame and obtain [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"footnotes":""},"class_list":["post-1996","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/comments?post=1996"}],"version-history":[{"count":3,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1996\/revisions"}],"predecessor-version":[{"id":4734,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1996\/revisions\/4734"}],"wp:attachment":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/media?parent=1996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}