{"id":6119,"date":"2015-08-07T09:00:08","date_gmt":"2015-08-07T13:00:08","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=6119"},"modified":"2015-08-06T08:57:24","modified_gmt":"2015-08-06T12:57:24","slug":"high-dimensional-visualization-with-bubbleplot","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2015\/08\/07\/high-dimensional-visualization-with-bubbleplot\/","title":{"rendered":"High-Dimensional Visualization with Bubbleplot"},"content":{"rendered":"<div class=\"content\"><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\/48005-bubbleplot-multidimensional-scatter-plots\"><tt>bubbleplot<\/tt><\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/6055857\">Ameya Deoras<\/a>.<\/p><p>Ameya was a fellow MathWorker and also helped us with this Pick of the Week blog. He's now working at a financial firm.<\/p><p>I'm always impressed with his MATLAB programs. They are extremely useful and very well written. One of my all-time favorites is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27075-intelligent-dynamic-date-ticks\">Intelligent Dynamic Date Ticks<\/a>, which I also highlighted as a <a href=\"https:\/\/blogs.mathworks.com\/pick\/2010\/04\/09\/dynamic-date-ticks\/\">Pick<\/a>. This was a must-have tool, especially before R2014b, when working with data represented as dates. In R2014b, we introduced a new data type <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/datetime.html\"><tt>datetime<\/tt><\/a>, which makes date handling (including plotting) much easier.<\/p><p>Back to this post. <tt>bubbleplot<\/tt> is a visualization function for high-dimensional data. If you have ever used <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/scatter.html\"><tt>scatter<\/tt><\/a> or <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/scatter3.html\"><tt>scatter3<\/tt><\/a>, you probably know that you can already plot four or five dimensional data. With <tt>bubbleplot<\/tt>, you'll be able to visualize up to 7 dimensions. Here's an example, borrowing from the examples Ameya provides with his entry.<\/p><p>We'll start with a shipping sample data from the <a href=\"https:\/\/www.mathworks.com\/products\/statistics\/\">Statistics and Machine Learning Toolbox<\/a>.<\/p><pre class=\"codeinput\">load <span class=\"string\">carsmall<\/span>\r\nOrigin = cellstr(Origin);\r\n\r\n<span class=\"comment\">% Create a table for easy overview<\/span>\r\nt = table(Acceleration,Horsepower,MPG,Weight,Model_Year,Cylinders,Origin);\r\nt(1:10,:)\r\n<\/pre><pre class=\"codeoutput\">ans = \r\n    Acceleration    Horsepower    MPG    Weight    Model_Year    Cylinders    Origin\r\n    ____________    __________    ___    ______    __________    _________    ______\r\n      12            130           18     3504      70            8            'USA' \r\n    11.5            165           15     3693      70            8            'USA' \r\n      11            150           18     3436      70            8            'USA' \r\n      12            150           16     3433      70            8            'USA' \r\n    10.5            140           17     3449      70            8            'USA' \r\n      10            198           15     4341      70            8            'USA' \r\n       9            220           14     4354      70            8            'USA' \r\n     8.5            215           14     4312      70            8            'USA' \r\n      10            225           14     4425      70            8            'USA' \r\n     8.5            190           15     3850      70            8            'USA' \r\n<\/pre><p>Then create a bubbleplot using these variables. For Color and Shape, the function is able to take categorical data as well. See the help for more information.<\/p><pre class=\"codeinput\">bubbleplot(t.Acceleration, t.Horsepower, t.MPG,<span class=\"keyword\">...<\/span><span class=\"comment\">  % X, Y, Z<\/span>\r\n    t.Weight, t.Model_Year, t.Cylinders,<span class=\"keyword\">...<\/span><span class=\"comment\">         % Size, Color, Shape<\/span>\r\n    Origin,<span class=\"keyword\">...<\/span><span class=\"comment\">                                      % Text<\/span>\r\n    <span class=\"string\">'FontSize'<\/span>, 6);\r\ngrid <span class=\"string\">on<\/span>\r\nxlabel(<span class=\"string\">'Acceleration'<\/span>)\r\nylabel(<span class=\"string\">'Horsepower'<\/span>)\r\nzlabel(<span class=\"string\">'MPG'<\/span>)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_bubbleplot\/potw_bubbleplot_01.png\" alt=\"\"> <p>The function is well-written, with good use of <a title=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/inputparser-class.html (link no longer works)\"><tt>inputParser<\/tt><\/a> and plenty of error checking. People wanting to learn good programming practices should have a look. If I were to add one suggestion, I would make it so that the function output (handle objects) gets returned only when it is asked for. When I call the function without an output argument, I don't want \"ans\" created. Just a minor suggestion.<\/p><p>Thanks for a cool visualization tool, Ameya. Hope you're doing well!<\/p><p><b>Comments<\/b><\/p><p>Give this a try, and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=6119#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/48005-bubbleplot-multidimensional-scatter-plots#comments\">comment<\/a> for Ameya.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_aa814cd782fb43ed8c023764fbf86184() {\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='aa814cd782fb43ed8c023764fbf86184 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' aa814cd782fb43ed8c023764fbf86184';\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        copyright = 'Copyright 2015 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 copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\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     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_aa814cd782fb43ed8c023764fbf86184()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2015a<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2015a<br><\/p><\/div><!--\r\naa814cd782fb43ed8c023764fbf86184 ##### 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\/48005-bubbleplot-multidimensional-scatter-plots |bubbleplot|>\r\n% by <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/6055857 Ameya\r\n% Deoras>.\r\n%\r\n% Ameya was a fellow MathWorker and also helped us with this Pick of the\r\n% Week blog. He's now working at a financial firm.\r\n%\r\n% I'm always impressed with his MATLAB programs. They are extremely useful\r\n% and very well written. One of my all-time favorites is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27075-intelligent-dynamic-date-ticks Intelligent\r\n% Dynamic Date Ticks>, which I also highlighted as a\r\n% <https:\/\/blogs.mathworks.com\/pick\/2010\/04\/09\/dynamic-date-ticks\/ Pick>.\r\n% This was a must-have tool, especially before R2014b, when working with\r\n% data represented as dates. In R2014b, we introduced a new data type\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/datetime.html |datetime|>,\r\n% which makes date handeling (including plotting) much easier.\r\n%\r\n% Back to this post. |bubbleplot| is a visualization function for\r\n% high-dimensional data. If you have ever used\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/scatter.html |scatter|> or\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/scatter3.html |scatter3|>, you\r\n% probably know that you can already plot four or five dimensional data.\r\n% With |bubbleplot|, you'll be able to visualize up to 7 dimensions. Here's\r\n% an example, borrowing from the examples Ameya provides with his entry.\r\n%\r\n% We'll start with a shipping sample data from the\r\n% <https:\/\/www.mathworks.com\/products\/statistics\/ Statistics and Machine\r\n% Learning Toolbox>.\r\n\r\nload carsmall\r\nOrigin = cellstr(Origin);\r\n\r\n% Create a table for easy overview\r\nt = table(Acceleration,Horsepower,MPG,Weight,Model_Year,Cylinders,Origin);\r\nt(1:10,:)\r\n\r\n%%\r\n% Then create a bubbleplot using these variables. For Color and Shape, the\r\n% function is able to take categorical data as well. See the help for more\r\n% information.\r\n\r\nbubbleplot(t.Acceleration, t.Horsepower, t.MPG,...  % X, Y, Z\r\n    t.Weight, t.Model_Year, t.Cylinders,...         % Size, Color, Shape\r\n    Origin,...                                      % Text\r\n    'FontSize', 6);  \r\ngrid on\r\nxlabel('Acceleration')\r\nylabel('Horsepower')\r\nzlabel('MPG')\r\n\r\n%%\r\n% The function is well-written, with good use of\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/inputparser-class.html\r\n% |inputParser|> and plenty of error checking. People wanting to learn good\r\n% programming practices should have a look. If I were to add one\r\n% suggestion, I would make it so that the function output (handle objects)\r\n% gets returned only when it is asked for. When I call the function without\r\n% an output argument, I don't want \"ans\" created. Just a minor suggestion.\r\n%\r\n% Thanks for a cool visualization tool, Ameya. Hope you're doing well!\r\n% \r\n% *Comments*\r\n%\r\n% Give this a try, and let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=6119#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/48005-bubbleplot-multidimensional-scatter-plots#comments\r\n% comment> for Ameya.\r\n\r\n##### SOURCE END ##### aa814cd782fb43ed8c023764fbf86184\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_bubbleplot\/potw_bubbleplot_01.png\" onError=\"this.style.display ='none';\" \/><\/div><p>Jiro's pick this week is bubbleplot by Ameya Deoras.Ameya was a fellow MathWorker and also helped us with this Pick of the Week blog. He's now working at a financial firm.I'm always impressed with... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2015\/08\/07\/high-dimensional-visualization-with-bubbleplot\/\">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\/6119"}],"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=6119"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/6119\/revisions"}],"predecessor-version":[{"id":6123,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/6119\/revisions\/6123"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=6119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=6119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=6119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}