{"id":3825,"date":"2012-09-07T09:00:19","date_gmt":"2012-09-07T13:00:19","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=3825"},"modified":"2012-09-07T00:12:24","modified_gmt":"2012-09-07T04:12:24","slug":"beeswarm-plot","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2012\/09\/07\/beeswarm-plot\/","title":{"rendered":"Beeswarm Plot"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/37105-plot-spread-points--beeswarm-plot-\"><tt>plotSpread<\/tt><\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/36283\">Jonas<\/a>.\r\n   <\/p>\r\n   <p>I always keep an eye out for interesting visualizations, and Jonas's <tt>plotSpread<\/tt> caught my attention. Last year, I <a href=\"https:\/\/blogs.mathworks.com\/pick\/2011\/10\/07\/box-plot-scatter-plot\/\">highlighted<\/a> a utility that overlayed jittered data points on top of box plots. <tt>plotSpread<\/tt> also allows you to visualize the distribution of data points using cloud of points, and the width of the jitter can represent\r\n      the number of points within the proximity of each other, i.e. the fatter the spread, the more points within that region.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">data = {randn(25, 1), randn(100, 1) + 1, randn(300, 1) - 0.5};\r\nplotSpread(data, <span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'xNames'<\/span>, {<span style=\"color: #A020F0\">'25 pts'<\/span>, <span style=\"color: #A020F0\">'100 pts'<\/span>, <span style=\"color: #A020F0\">'300 pts'<\/span>}, <span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'distributionMarkers'<\/span>, {<span style=\"color: #A020F0\">'o'<\/span>, <span style=\"color: #A020F0\">'+'<\/span>, <span style=\"color: #A020F0\">'.'<\/span>});<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_beeswarmplot\/potw_beeswarmplot_01.png\"> <p>The plot can be customized in many different ways, and Jonas includes a detailed help for the various options. I was happy\r\n      to see him use the <a title=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/inputparserclass.html (link no longer works)\"><tt>inputParser<\/tt><\/a> to error-check the numerous optional inputs he had. In fact, more than half of his ~500 lines of code is for error-checking.\r\n      Thanks for making the utility robust!\r\n   <\/p>\r\n   <p><b>Comments<\/b><\/p>\r\n   <p>Give it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=3825#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/37105-plot-spread-points--beeswarm-plot-#comments\">comment<\/a> for Jonas.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_9c51b0f9868e4a8e92b11cd7f0c2f83b() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='9c51b0f9868e4a8e92b11cd7f0c2f83b ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 9c51b0f9868e4a8e92b11cd7f0c2f83b';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Jiro Doke';\r\n        copyright = 'Copyright 2012 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_9c51b0f9868e4a8e92b11cd7f0c2f83b()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.14<br><\/p>\r\n<\/div>\r\n<!--\r\n9c51b0f9868e4a8e92b11cd7f0c2f83b ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\r\n% Jiro>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/37105-plot-spread-points--beeswarm-plot- |plotSpread|>\r\n% by <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/36283\r\n% Jonas>.\r\n%\r\n% I always keep an eye out for interesting visualizations, and Jonas's\r\n% |plotSpread| caught my attention. Last year, I\r\n% <https:\/\/blogs.mathworks.com\/pick\/2011\/10\/07\/box-plot-scatter-plot\/\r\n% highlighted> a utility that overlayed jittered data points on top of box\r\n% plots. |plotSpread| also allows you to visualize the distribution of data\r\n% points using cloud of points, and the width of the jitter can represent\r\n% the number of points within the proximity of each other, i.e. the fatter\r\n% the spread, the more points within that region.\r\n\r\ndata = {randn(25, 1), randn(100, 1) + 1, randn(300, 1) - 0.5};\r\nplotSpread(data, ...\r\n    'xNames', {'25 pts', '100 pts', '300 pts'}, ...\r\n    'distributionMarkers', {'o', '+', '.'});\r\n\r\n%%\r\n% The plot can be customized in many different ways, and Jonas includes a\r\n% detailed help for the various options. I was happy to see him use the\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/inputparserclass.html\r\n% |inputParser|> to error-check the numerous optional inputs he had. In\r\n% fact, more than half of his ~500 lines of code is for error-checking.\r\n% Thanks for making the utility robust!\r\n%\r\n% *Comments*\r\n%\r\n% Give it a try and let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=3825#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/37105-plot-spread-points--beeswarm-plot-#comments\r\n% comment> for Jonas.\r\n\r\n##### SOURCE END ##### 9c51b0f9868e4a8e92b11cd7f0c2f83b\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Jiro's pick this week is plotSpread by Jonas.\r\n   \r\n   I always keep an eye out for interesting visualizations, and Jonas's plotSpread caught my attention. Last year, I highlighted a utility... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2012\/09\/07\/beeswarm-plot\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/3825"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=3825"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/3825\/revisions"}],"predecessor-version":[{"id":3829,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/3825\/revisions\/3829"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=3825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=3825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=3825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}