<div>Skewed data prevail in real life. Unless you observe trivial or near constant processes data is skewed one way or another due to outliers, long tails, errors or something else. Such effects create problems in visualizations when a few data elements are much larger than the rest.</div>
<div>Consider<span> </span><a rel="nofollow noopener" href="http://goo.gl/2nDR0p" target="_blank">U.S. 2016 merchandise trade partner balances</a><span> </span>data set where each point is a country with 2 features: U.S. imports and exports against it:</div>
<table cellspacing="0" align="center" cellpadding="0">
<tr><td></td></tr>
<tr><td><br></td></tr>
</table>
<div>
<span><span>Suppose we decided to visualize top 30 U.S trading partners using<span> </span></span><a rel="nofollow noopener" href="http://en.wikipedia.org/wiki/Bubble_chart" target="_blank">bubble chart</a><span>, which simply is a 2D<span> </span></span><a rel="nofollow noopener" href="http://en.wikipedia.org/wiki/Scatter_plot" target="_blank">scatter plot</a><span><span> </span>with the third dimension expressed through point size. Then U.S. trade partners become disks with imports and exports for<span> </span></span><i>xy</i><span><span> </span>coordinates and trade balance (</span><i>abs(export - import)</i></span><span><span>) for size:</span> </span>
</div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div>
 </div>
<div>
<span><span>China, Canada, and Mexico run far larger balances compared to the other 27 countries which causes most data points to collapse into crowded lower left corner. One way to &quot;solve&quot; this problem is to eliminate 3 mentioned outliers from the picture:</span></span><br><br><span><span> </span></span> </div>
<div> While this plot does look better it no longer serves its original purpose of displaying<span> </span>all<span> </span>top trading partners. And undesirable effect of outliers though reduced still presents itself with new ones: Japan, Germany, and U.K. So let us bring all countries back into the mix by trying logarithmic scale.</div>
<div>Quick refresher from algebra.<span> </span><a rel="nofollow noopener" href="https://en.wikipedia.org/wiki/Logarithm" target="_blank">Log function</a><span> </span>(in this example log base 10 but the same applies to natural log or log base 2) is commonly used to transform positive real numbers. All because of its property of mapping multiplicative relationships into additive ones. Indeed, given numbers<span> </span><i>A</i>,<span> </span><i>B</i>, and<span> </span><i>C<span> </span></i>such that<br><br><div>`A*B=C and A,B,C > 0`<br>
</div>
<br>applying <i>log<span> </span></i> results in additive relationship:<br><br><div>`log(A) + log(B) = log(C)`<br>
</div>
<div>
<br><span><span>For example, let<span> </span></span></span><i>A=100</i><span>,<span> </span></span><i>B=1000</i><span>, <span>and</span><span> </span></span><i>C=100000</i><span><span> </span><span>then</span></span><br><span><span> </span></span><br><div>`100 * 1000 = 100000`<br><br>
</div>so that after transformation it becomes <br><div>
<br>`log(100) + log(1000) = log(100000)`  or   `2 + 3 = 5`<br><br><span>Observe this on 1D plane:</span><br><br><div><a href="https://1.bp.blogspot.com/-btZe8w3MYng/WU06zh_PX5I/AAAAAAAA4w0/seYrL970fi4uJ-ACbv9irQU5aqveFa5uACLcBGAs/s1600/before-log-transform.png"></a></div>
<br><div><a href="https://2.bp.blogspot.com/-6-NlNdLf5VY/WU07A8PwZtI/AAAAAAAA4w4/PbJbZocQ9jMoVyVjWMnV_DRmJv7ipY-fQCLcBGAs/s1600/after-log-transform.png"> </a></div>
<div><span><div><br></div></span></div>
<span>Logarithmic scale is simply a log transformation applied to all feature's values before plotting them. In our example we used it on both trading partners' features - imports and exports which gives bubble chart new look:</span>
</div>
<div>
<span> <div><a href="https://2.bp.blogspot.com/-3yQX6xBuM-E/WU079kyApmI/AAAAAAAA4xA/6QyYOJs5zPw5TiRwug_7_gMrVoch0wuwwCLcBGAs/s1600/US-Merchandise-Trade-Balance-top30-log.png"></a></div></span><span> </span>
</div>
<div><span>The same data displayed on logarithmic scale appear almost uniform but not to forget the farther away points from 0 the more orders of magnitude they are apart on actual scale (observe this by scrolling back to the original plot). The main advantage of using log scale in this plot is ability of observing relationships between all top 30 countries without loosing the whole picture and avoiding collapsing smaller points together.</span></div>
<div><span> </span></div>
<div><span><span>For more detailed discussion of logarithmic scale refer to<span> </span></span><a rel="nofollow noopener" href="https://www.forbes.com/sites/naomirobbins/2012/01/19/when-should-i-use-logarithmic-scales-in-my-charts-and-graphs/#60dca2055e67" target="_blank">When Should I Use Logarithmic Scales in My Charts and Graphs?</a><span><span> </span>Oh, and how about that trade deficit with China?</span></span></div>
<div><span><span> </span></span></div>
<div>
<span><span><span><span><i>This is a re-post from the original <a href="https://www.linkedin.com/pulse/logarithmic-scale-action-example-gregory-kanevsky">blog</a> on LinkedIn.</i></span></span></span> </span><br><span></span>
</div>
</div>
</div>