<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/why-you-should-master-the-small-multiple-chart/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.sharpsightlabs.com/blog/master-small-multiple/"> r-bloggers | SHARP SIGHT</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I’ve often said that the foundation of data science <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/first-step-data-science-top-performer/" target="_blank">is data analysis</a>.</p>
<p>That’s not to say that data analysis and data science are 100% synonymous (they’re not), but rather that you need to master the basic tools of data analysis before you can get into the more advanced skills that make up data science.</p>
<p>Said more simply: if you want too be a great data scientist, you need to be a great data analyst first.</p>
<h1>Data analysis is often about making comparisons</h1>
<p>In many cases, data analysis is a game of comparison. </p>
<p>As the great Edward Tufte noted, when we analyze data, we’re often trying to answer the question “Compared to what?”</p>
<blockquote>
<p>
At the heart of quantitative reasoning is a single question: Compared to what?</p>
<p>– Edward Tufte
</p>
</blockquote>
<p>When we analyze data, we’re frequently comparing things. Comparing one bar in a bar chart to another bar. Comparing one category to another. Comparing one variable to another. Comparing a variable to itself, with different constraints or filters. Comparing one model to another, or comparing a model with one set of parameters/assumptions/etc to another model with a different set of parameters/assumptions/etc.</p>
<p>The closer you look at data analysis, sometimes it just looks like comparisons all the way down the rabbit hole.</p>
<p>The fact is, if you want to be a great data scientist, you need to be a great data analyst. And if you want to be a great data analyst, you need to be a master at making comparisons with data.</p>
<p>Arguably the best tool to do this, is the small multiple chart.</p>
<h1>Quick introduction to small multiples</h1>
<p>So what is the small multiple?</p>
<p>It’s OK if you don’t know. The small multiple is not used that often (which I will discuss in a moment).</p>
<p><a rel="nofollow" href="http://www.sharpsightlabs.com/blog/small-multiples-ggplot/" target="_blank">The small multiple</a> is a chart that essentially creates several similar, small panels of the same chart type, where each panel is a little different. </p>
<p>Frequently, each panel represents a different subset of the data. The different panels will represent a subset for a specific category (of a categorical variable). There are also other, more complicated small multiple designs where we subset by two different categorical variables, and each panel represents a unique combination of categories for those categoricals.</p>
<p>Let’s take a look at a simple example.</p>
<p>Before showing you a small multiple, let’s just <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/how-to-create-a-scatterplot-in-r/" target="_blank">take a look at a simple scatterplot</a>:</p>
<pre class="wp-code-highlight">
library(ISLR)

ggplot(data = Auto, aes(x = horsepower, y = acceleration)) +
  geom_point() 
</pre>
<p><a rel="nofollow" href="http://www.sharpsightlabs.com/join-newsletter-get-crash-course/" target="_blank"><br>
<img alt="" src="https://i1.wp.com/www.sharpsightlabs.com/wp-content/uploads/2018/04/auto_horsepower-by-acceleration.png?w=450" class="wp-image-3419" data-recalc-dims="1"><br>
</a></p>
<p>This is a fairly straightforward chart. Horsepower vs acceleration plotted as a scatterplot.</p>
<p>We can see a basic relationship between these two variables. However, there might be more to see. There is a variety of ways to slice and dice this dataset, and if we will examine different “slices” of the data, we might find something interesting or insightful.</p>
<p>A simple way to “slice” the data and would be to repeatedly <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/how-to-create-a-scatterplot-in-r/" target="_blank">subset your data</a>. You could subset the data several times, and make a separate chart for every subset.</p>
<p>However, a much faster way is to simply make a small multiple version of this chart, broken out by a third categorical variable.</p>
<p>Let’s do that. Here’ we’ll break out the above scatterplot by the “cylinders” variable.</p>
<pre class="wp-code-highlight">
ggplot(data = Auto, aes(x = horsepower, y = acceleration)) +
  geom_point() +
  facet_wrap(~cylinders)
</pre>
<p><a rel="nofollow" href="http://www.sharpsightlabs.com/join-newsletter-get-crash-course/" target="_blank"><br>
<img sizes="(max-width: 600px) 100vw, 600px" src="https://i1.wp.com/www.sharpsightlabs.com/wp-content/uploads/2018/04/auto_horsepower-by-acceleration-by-cyl-600x323.png?w=450" alt="" class="wp-image-3420" data-recalc-dims="1"><br>
</a></p>
<p>What have we done here?</p>
<p>We broke our original chart out into five separate but similar charts, or “panels.” We broke it out on a categorical variable, such that each panel of the chart is a separate version of the initial chart for a particular value of the categorical variable. So we have one scatterplot for 3-cylinder cars, one scatterplot for 4-cylinder cars, and so on. Each panel is effectively a subsetted version of our initial scatterplot for a particular value of “cylinders”. </p>
<p>Essentially, this technique created multiple small panels with different versions of the same chart.</p>
<p>Small panels. Multiple panels. </p>
<p>Small multiple. </p>
<p>Get it?</p>
<h1>Small multiples help you make quick comparisons</h1>
<p>Take another look at the first <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/how-to-create-a-scatterplot-in-r/" target="_blank">simple scatterplot</a> that we just made, and then look at the small multiple.</p>
<p>It’s immediately obvious that there are differences between the panels of the small multiple chart. We couldn’t see these differences in the initial simple scatterplot, because all of the data were lumped together into a single chart. But by breaking the chart out into several small panels, we can suddenly see that there are differences in the data for different values of the cylinder variable.</p>
<p>… differences that we couldn’t see initially, in the original chart.</p>
<p>… differences that might be important (depending on our analytical goals).</p>
<p>This is why you need to master the small multiple design: The small multiple enables you to <strong><em>see</em></strong> differences. You are literally seeing the original chart in a new way. Seeing the data more clearly. Seeing with **ahem** sharper sight. </p>
<p>Small multiples, when used properly, enable you to make very quick comparisons across categorical classes in a dataset and see important differences. </p>
<p>When you need to analyze, visualize, or otherwise explore a dataset – and drill down into a dataset to find insights – the small multiple design is a powerful tool that you need to use.</p>
<h1>The small multiple is wildly underused</h1>
<p>Because they are so useful for making visual comparisons, I think the small multiple design is quite frequently the best tool for finding insights in data.</p>
<p>And I’m not the only person. </p>
<p>Let’s go back to that quote from the data visualization guru, Tufte. This time, I’ll give you the full quote:</p>
<blockquote>
<p>
At the heart of quantitative reasoning is a single question: Compared to what?</p>
<p>Small multiple designs, multivariate and data bountiful, answer directly by visually enforcing comparisons of changes, of the differences among objects, of the scope of alternatives. For a wide range of problems in data presentation, small multiples are the best design solution.</p>
<p>– Edward Tufte<br>
</blockquote>
<p>Read that again: “for a wide range of problems … small multiples are the best design solution.”</p>
<p>While we can’t take the opinion of one man as gospel, I must say that I agree with Tufte. Small multiples frequently are the best tool for making comparisons in data. They are a tool for directly comparing across groups. This means, that in many, many cases, they are actually the best tool for making comparisons, making distinctions, drilling into your data, and ultimately finding insights.</p>
<p>So when you use a simple tool like the bar chart, <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/histogram-in-r-basic/" target="_blank">the histogram</a>, <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/how-to-create-a-scatterplot-in-r/" target="_blank">the scatterplot</a>, and <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/line-chart-ggplot2-amzn/" target="_blank">the line chart</a>, there’s frequently an opportunity to further “drill into” the data by breaking the chart out into small multiples.</p>
<p>But even if the small multiple is often one of the best tools for data analysis and exploration, small multiples are wildly underused. I would estimate that only one out of ten data analysts or data scientists actually use the technique.</p>
<p>Part of the reason that they’re so rarely used is that they’re typically just hard to create with most toolsets. In base R, they’re a little hard to create (and a little ugly). And don’t get me started on trying to do them in Excel. You can create small multiples in Excel, but the process for creating them is tedious at best. Because they are hard to create with most tools, they are just not used very often.</p>
<p>This is excellent news for you, being the disciplined data science student that you are.</p>
<p>Because they are so powerful and so underused, you can distinguish yourself by learning and using the small multiple. Your analyses will be more insightful, and you will personally be more effective in getting things done compared to people who don’t use them.</p>
<p>If you want to be a great data analyst and a great data scientist, you should learn and master the small multiple.</p>
<h1>How to use the small multiple</h1>
<p>Ok, you should get it by now. The small multiple is a powerful tool.</p>
<p>Let’s quickly take a look at a few examples of how this is used.</p>
<h3>Data Exploration</h3>
<p>One of the most frequent uses for the small multiple chart is for <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/data-analysis-example-r-supercars-part2/" target="_blank">simple data exploration</a>.</p>
<p>When you initially approach a new dataset, you’ll want to get an idea of what’s in it. </p>
<p>You may be looking for something in particular, but more often than not, you’re just trying to get a sense of how the data are structured; if there any issues with the data; and if there is anything “interesting” that needs to be investigated further.</p>
<p>One of the first things you’ll do when you’re <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/data-analysis-example-r-supercars-part2/" target="_blank">exploring a dataset</a>, is you will create histograms or density plots of your variables. </p>
<p>You’ll also sometimes want to create subsetted density plots for different categories or subsets of your data.</p>
<p>This is a perfect use case for the small multiple design.</p>
<p>Let’s take a look.</p>
<pre class="wp-code-highlight">
Credit %>% 
  ggplot(aes(x = Income)) +
    geom_density() +
    facet_grid(Student ~ Married)
</pre>
<p><a rel="nofollow" href="http://www.sharpsightlabs.com/join-newsletter-get-crash-course/" target="_blank"><br>
<img sizes="(max-width: 600px) 100vw, 600px" src="https://i1.wp.com/www.sharpsightlabs.com/wp-content/uploads/2018/04/income-density_student-by-married-600x359.png?w=450" alt="" class="wp-image-3421" data-recalc-dims="1"><br>
</a></p>
<p>We’ve used the small multiple design to break out the density plot into several new plots based on two categorical variables. This gives us a new view of the data and helps us “look closer” for new insights.</p>
<p>Now, when you do this, sometimes you find something, and sometimes you don’t.</p>
<p>The important thing though, is that you commonly need to create a lot of these charts. You need to “slice and dice” your data a variety of ways. </p>
<p>The small multiple gives you a way to do this. The small multiple gives you a way to look at different cuts of your dataset to see if there’s anything interesting or in need of further exploration.</p>
<h3>Data Visualization</h3>
<p>Beyond simple, preliminary data exploration, you can also use the small multiple design to visualize and present results. In particular, the small multiple design gives you a way to convey a lot of information in a single chart.</p>
<p>A great example of this is a <a rel="nofollow" href="http://andrewgelman.com/2009/07/15/hard_sell_for_b/" target="_blank">data visualization by Andrew Gelman</a>:</p>
<p><img sizes="(max-width: 600px) 100vw, 600px" src="https://i1.wp.com/www.sharpsightlabs.com/wp-content/uploads/2018/04/voucher-small-multiple-map_gelman-600x600.png?w=450" alt="" class="wp-image-3422" data-recalc-dims="1"></p>
<p>This is a great visualization. </p>
<p>It conveys vast amounts of information in a small, well contained visualization. If you look at it, you can clearly see information about the intersection of various categories. You can quickly view a different “small” version of the map for different combinations of income and ethnic background. </p>
<p>The small multiple technique will increase your data visualization skill, because it will give you the ability to display vast amounts of information quickly and concisely. </p>
<h3>Data preparation (prior to machine learning)</h3>
<p>Small multiples are also excellent for a special type of data exploration: exploring data for data preparation, <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/data-analysis-machine-learning-example-part2/" target="_blank">prior to building a machine learning model</a>.</p>
<p>When you build a machine learning model, it’s very common that you need to clean, reshape, or prepare your data. For example, you’ll need to identify and possibly deal with outliers. You will need to identify skewness in your data (and possibly deal with it). You’ll sometimes need to verify that your input variables are normally distributed. </p>
<p>One way to identify and diagnose these potential issues is by using data exploration techniques.</p>
<p>Here’s a quick example.</p>
<p>Let’s say you approach a new dataset with the goal of building a regression model. One of the first things you might want to do is examine the numeric variables and look for skewness, outliers, etc.</p>
<p>To do this quickly, you could simply subset down to the numeric variables, and plot those numeric variables as histograms or density plots.</p>
<pre class="wp-code-highlight">
library(caret)
data(Sacramento)

Sacramento %>% 
  select_if(is.numeric) %>% 
  gather() %>% 
  ggplot(aes(x = value)) +
    geom_density() +
    facet_wrap(~key, scales = 'free')
</pre>
<p><a rel="nofollow" href="http://www.sharpsightlabs.com/join-newsletter-get-crash-course/" target="_blank"><br>
<img sizes="(max-width: 600px) 100vw, 600px" src="https://i0.wp.com/www.sharpsightlabs.com/wp-content/uploads/2018/04/sacramento-density-small-multiple-600x318.png?w=450" alt="" class="wp-image-3423" data-recalc-dims="1"><br>
</a></p>
<p>It’s true that you could do these one at a time as individual density plots, but it’s much faster if you just use the small multiple design.</p>
<p>Moreover, if you have dozens or hundreds of numeric variables, it will be highly impractical to plot a density chart for each variable, one by one. So to quickly solve this problem, you can just use the small multiple.</p>
<p>If you want to eventually learn machine learning, this is something you need to be able to do. You need to be able to plot the predictor distributions of your variables. The small multiple design makes this straightforward.</p>
<h1>Small multiples are easy with <code>ggplot2</code></h1>
<p>Long time readers will know that I love <code>ggplot2</code> and the tidyverse.</p>
<p>I want to be clear about this: I don’t strongly recommend the tidyverse toolkit just because everyone else is using it or out of some unthinking loyalty to its creators.</p>
<p>Quite the opposite: if the creators of the tidyverse did something that I firmly disagreed with, I would be the first to say it.</p>
<p>No. I recommend the tidyverse because it is extremely well designed. It is so well designed that things like the small multiple chart – which is really hard to make with almost any other toolkit – is as simple as adding one more line of code. </p>
<p>That’s it. One extra line.</p>
<p>Let me show you by reviewing our initial example:</p>
<p>In the first example in this blog post, we made a scatterplot.</p>
<pre class="wp-code-highlight">
library(ISLR)

ggplot(data = Auto, aes(x = horsepower, y = acceleration)) +
  geom_point() 
</pre>
<p><a rel="nofollow" href="http://www.sharpsightlabs.com/join-newsletter-get-crash-course/" target="_blank"><br>
<img alt="" src="https://i1.wp.com/www.sharpsightlabs.com/wp-content/uploads/2018/04/auto_horsepower-by-acceleration.png?w=450" class="wp-image-3419" data-recalc-dims="1"><br>
</a></p>
<p>This is a very simple chart in <code>ggplot2</code>. We’re mapping horsepower to the x axis and acceleration to the y axis.</p>
<p>But with the addition of only a single extra line of code, we can break this out into small panels; one extra line of code transforms a simple scatterplot into a small multiple chart:</p>
<pre class="wp-code-highlight">
ggplot(data = Auto, aes(x = horsepower, y = acceleration)) +
  geom_point() +
  facet_wrap(~cylinders)
</pre>
<p><a rel="nofollow" href="http://www.sharpsightlabs.com/join-newsletter-get-crash-course/" target="_blank"><br>
<img sizes="(max-width: 600px) 100vw, 600px" src="https://i1.wp.com/www.sharpsightlabs.com/wp-content/uploads/2018/04/auto_horsepower-by-acceleration-by-cyl-600x323.png?w=450" alt="" class="wp-image-3420" data-recalc-dims="1"><br>
</a></p>
<p>We’ve taken the original chart and broken it out on the cylinder variable using the line <code>facet_wrap(~cylinders)</code>.</p>
<p>Essentially, ggplot2 enables you to create small multiple charts with ease. </p>
<p>If you aren’t already using <code>ggplot2</code> and the tidyverse, I highly recommend them.</p>
<p>Do you want to be a great data scientist? Learn data analysis.</p>
<p>Want to be a great data analyst? You need the small multiple design in your toolkit.</p>
<p>… And if you want to quickly and effortlessly use the small multiple technique, you should <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/start-with-data-visualization-manipulation/" target="_blank">learn some <code>ggplot2</code></a>.</p>
<h1>Discover how to master data science</h1>
<p>Mastering data science takes practice and hard work. </p>
<p>Don’t try to figure it out alone. </p>
<p><a rel="nofollow" href="http://www.sharpsightlabs.com/join-newsletter-get-crash-course/" target="_blank">Sign up now</a>, and discover how to master data science. </p>
<p>In our tutorials, we will help you learn and master the tools you need to be a top-performing data scientist.</p>
<p>Moreover, if you sign up now, you’ll get access to our <strong>free</strong> Data Science Crash Course.</p>
<p>In the Data Science Crash Course, you’ll learn:</p>
<ul>
<li>a step-by-step data science learning plan </li>
<li>the 1 programming language you <i>need to</i> learn </li>
<li>3 essential data visualizations</li>
<li>how to do data manipulation in R</li>
<li>how to get started with machine learning</li>
<li>the difference between machine learning and statistics</li>
</ul>
<p><a rel="nofollow" href="http://www.sharpsightlabs.com/join-newsletter-get-crash-course/" target="_blank">
<p><strong>SIGN UP NOW</strong></p>
<p></p></a>
<p>The post <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/master-small-multiple/" target="_blank">Why you should master the small multiple chart</a> appeared first on <a rel="nofollow" href="http://www.sharpsightlabs.com/" target="_blank">SHARP SIGHT</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.sharpsightlabs.com/blog/master-small-multiple/"> r-bloggers | SHARP SIGHT</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/kNWcuoQLoV4" height="1"></a></div>