-
Notifications
You must be signed in to change notification settings - Fork 0
/
charts.html
448 lines (389 loc) · 18.8 KB
/
charts.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<title>Charts</title>
<script src="site_libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/cosmo.min.css" rel="stylesheet" />
<script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<link href="site_libs/highlightjs-9.12.0/textmate.css" rel="stylesheet" />
<script src="site_libs/highlightjs-9.12.0/highlight.js"></script>
<meta name="description" content="Learn how to choose the most effective data visualisation options for your research data from the OxShef Charts webste. OxShef is a collaboration between University of Oxford and University of Sheffield." />
<link rel="icon" type="image/png" href="images/favicon.png" />
<script type="text/javascript" src="js/rmarkdown.js"></script>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<script type="text/javascript">
if (window.hljs) {
hljs.configure({languages: []});
hljs.initHighlightingOnLoad();
if (document.readyState && document.readyState === "complete") {
window.setTimeout(function() { hljs.initHighlighting(); }, 0);
}
}
</script>
<style type="text/css">
h1 {
font-size: 34px;
}
h1.title {
font-size: 38px;
}
h2 {
font-size: 30px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 18px;
}
h5 {
font-size: 16px;
}
h6 {
font-size: 12px;
}
.table th:not([align]) {
text-align: left;
}
</style>
<link rel="stylesheet" href="css/rmarkdown.css" type="text/css" />
<link rel="stylesheet" href="css/title-0px.css" type="text/css" />
</head>
<body>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
height: auto;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
</style>
<div class="container-fluid main-container">
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
</script>
<!-- code folding -->
<div id="rStudioHeader" class="alwaysShrunk">
<div class="innards bandContent">
<div>
<a class="menuItem" href="index.html">OxShef: Charts</a>
</div>
<div id="menu">
<div id="menuToggler"></div>
<div id="menuItems">
<a class="menuItem" href="training-tutorials-and-templates.html">Training, Tutorials and Templates</a>
<a class="menuItem" href="charts.html">Charts</a>
<a class="menuItem" href="geoviz_maps.html">Geoviz (Maps)</a>
<a class="menuItem" href="networks.html">Networks</a>
<a class="menuItem" href="timeseries.html">Time Series</a>
<a class="menuItem" href="other.html">Other Visualisations</a>
<a class="menuItem gitHub" href="https://github.com/ox-it/OxfordIDN_charts"></a>
<a class="menuItem gitHubText" href="https://github.com/ox-it/OxfordIDN_charts">Source on GitHub</a>
</div>
</div>
</div>
</div>
<style type="text/css">
#TOC {
margin-left: 35px;
margin-top: 90px;
}
</style>
<script type="text/javascript">
$(".main-container").removeClass("main-container").removeClass("container-fluid").addClass("footerPushDown");
</script>
<div id="pageContent" class="standardPadding">
<div class="articleBandContent">
<style type="text/css">
.title {
display: none;
}
#disqus_thread {
display: none;
}
</style>
<div class="fluid-row" id="header">
<h1 class="title toc-ignore">Charts</h1>
</div>
<div id="charts-and-plots" class="section level1 tabset">
<h1>Charts and Plots</h1>
<p>Charts are the most common type of data visualisation, and certainly the most varied. However, it’s important to note that many readers will be confused by chart types that they have not seen before. Charts should be as easy to consume as possible. In general, a <strong>chart is used to present/compare data</strong> and a <strong>plot is used in the analysis of variables</strong>.</p>
<p>These are the most widely used easy to create and read charts; column charts, barcharts, piecharts, scatter plots and histograms.</p>
<center>
<img src='images/gg_age_col.png' width='15%'></img> <img src='images/gg_continents_bar.png' width='14%'></img> <img src='images/gg_age_pie.png' width='15%'></img> <img src='images/gg_iris_scatter.png' width='15%'></img> <img src='images/gg_diamonds_histogram.png' width='15%'></img>
</center>
<div id="chart-purpose" class="section level2">
<h2>Chart Purpose</h2>
<p>When designing a data visualisation you must think carefully about <strong>the story the dataviz tells</strong> your reader, or <strong>what questions does this dataviz answer?</strong> For simplicity, let’s use the excellent <a href="http://ft-interactive.github.io/visual-vocabulary/">Financial Time’s Visual Vocabulary</a> to create four types of story we can tell:</p>
<div class="row">
<div class="col-sm-6">
<ul>
<li>Comparison/Ranking/Magnitude Stories:
<ul>
<li>How much data is there?</li>
<li>How many cateogires are there in a dataset?</li>
<li>What percentage of the data belongs to each category?</li>
<li>Which category has the <em>most</em> items in it?</li>
</ul></li>
</ul>
</div>
<div class="col-sm-6">
<ul>
<li>Deviation Stories:
<ul>
<li>What lead did candidate X have in the election?</li>
<li>In which regions did candidate X lead over candidate Y?</li>
</ul></li>
</ul>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<ul>
<li>Correlation Stories:
<ul>
<li>Are variables X and Y correlated?</li>
<li>How well does your model fit your data?</li>
</ul></li>
</ul>
</div>
<div class="col-sm-6">
<ul>
<li>Distribution Stories:
<ul>
<li>What’s the age distribution in country X?</li>
<li>How does the age distribution vary between country X and Y?</li>
<li>What are the min and max values for each category in your data?</li>
</ul></li>
</ul>
</div>
</div>
<div id="example-stories-brexit-referendum-2016" class="section level3">
<h3>Example Stories: Brexit Referendum 2016</h3>
<p>To demonstrate the different types of stories we can tell with charts, let’s consider a public dataset; the results of the <a href="https://www.electoralcommission.org.uk/find-information-by-subject/elections-and-referendums/past-elections-and-referendums/eu-referendum/electorate-and-count-information">United Kingdom’s Brexit Referendum</a>. In the referendum, voters were asked to select between one of two options; Remain a member of the European Union or Leave the European Union.</p>
<ul>
<li><strong>Who won?</strong> This is a magnitude story, we care about whether Remain or Leave got more of the vote. A horizontal barchart is an excellent choice for this story, note it’s important to order the bars from largest to smallest. <a href="http://ft-interactive.github.io/visual-vocabulary/">See the Financial Time’s Visual Vocabulary for more example dataviz.</a></li>
</ul>
<p><img src="charts_files/figure-html/unnamed-chunk-6-1.png" width="384" style="display: block; margin: auto;" /></p>
<ul>
<li><strong>How did voter turnout compare between the regions of the UK?</strong> This is a comparison story, note that if there’s a sensible way to rank values in your data it will make the dataviz easier to read. While a horizontal barchart could work for this data, we’ve chosen to use a horizontal lollipop chart as we care about the voter turn out values and not ‘which region had the biggest impact on the referendum’. <a href="http://ft-interactive.github.io/visual-vocabulary/">See the Financial Time’s Visual Vocabulary for more example dataviz.</a></li>
</ul>
<p><img src="charts_files/figure-html/unnamed-chunk-7-1.png" width="480" style="display: block; margin: auto;" /></p>
<ul>
<li><strong>How did the results vary between regions?</strong> This is a deviation question, as we’re asking what is the variance from 50:50 for each region. Stacked barcharts are very good options for this purpose, as always with barcharts the order of the categories matters. The first chart is a very good chart if you have the specific question, “How did Leaves margin vary between regions”. <a href="http://ft-interactive.github.io/visual-vocabulary/">See the Financial Time’s Visual Vocabulary for more example dataviz.</a></li>
</ul>
<p><img src="charts_files/figure-html/unnamed-chunk-8-1.png" width="960" style="display: block; margin: auto;" /></p>
<ul>
<li><strong>Does the vote margin depend on region populaton?</strong> This is a (fairly silly) correlation question, as we’re asking do larger regions tend to have a smaller/larger margins. Scatter plots are the most useful type of chart for these questions. In general, a <em>chart</em> is used to present/compare data and a <em>plot</em> is used in the analysis of variables. <a href="http://ft-interactive.github.io/visual-vocabulary/">See the Financial Time’s Visual Vocabulary for more example dataviz.</a></li>
</ul>
<p><img src="charts_files/figure-html/unnamed-chunk-9-1.png" width="960" style="display: block; margin: auto;" /></p>
<ul>
<li><strong>How do the populations of the different constituencis vary?</strong> This is a distribution story, as we want readers to understand the minimum, maximum and “average” constituency population sizes. <a href="http://ft-interactive.github.io/visual-vocabulary/">See the Financial Time’s Visual Vocabulary for more example dataviz.</a></li>
</ul>
<p><img src="charts_files/figure-html/unnamed-chunk-10-1.png" width="960" style="display: block; margin: auto;" /></p>
</div>
</div>
<div id="types-of-data" class="section level2">
<h2>Types of Data</h2>
<p>Chart selection is heavily dependent on what <strong>types</strong> of data you have. Many dataviz tools automatically recommend charts to you based on the data type definitions below. Let’s consider an example dataset:</p>
<blockquote>
<p>You’ve collected exam results from an exam with 100 questions, taken by 200 students. In the data you have three columns; grade, number of correct responses, and percentage of correct responses.</p>
</blockquote>
<center>
<img src='images/gg_types_of_data.png' width='500px'></img>
</center>
<ul>
<li><p>Grades: This is a <strong>categorical</strong> and <strong>discrete variable</strong> as there are a limited set of available values. Because the <em>order</em> of these values is important (i.e. “Fail” should always be displayed before “Pass”) this is also an <strong>ordinal variable</strong>.</p></li>
<li><p>Number of correct responses: This is a <strong>discrete variable</strong> as students can only answer an integer number of questions correctly.</p></li>
<li><p>Percentage of correct responses: This is a <strong>continuous variable</strong> as results can vary between 0 - 100%. However, <em>practically</em> this is a discrete variable .</p></li>
</ul>
<p>A common issue with discrete variables masquerading as continuous variables is weird-looking histograms that are often not fit for purpose; <strong>the charts below</strong> (histogram, violin chart, column chart) all display the distribution of exam result percentages differently. The “best” chart of the three is dependent on the <strong>story the chart is telling</strong>.</p>
<center>
<img src="charts_files/figure-html/unnamed-chunk-12-1.png" width="768" />
</center>
<p>In general, this is sufficient knowledge about variables to get the most from other more detailed resources. It’s important to be careful with <strong>ordered ordinal variables</strong> as their intrinsic order must be well presented in the dataviz.</p>
<div id="recommended-reading" class="section level3">
<h3>Recommended Reading</h3>
<p>As mentioned above, many charting tools automatically choose the most appropriate charts based on the type of data you have. This is a fairly mature field of research, commonly called <em>graphical perception theory</em>. Cleveland and McGill’s seminal paper in 1987 [<a href="http://doi.org/10.2307/2288400">DOI:10.2307/2288400</a>] was the first to systematically explore how the human perception system processes graphical data and continues to be relevant today.</p>
<div class="row">
<div class="col-sm-7">
<p>In addition to automatically recommending charts, tools like ReVision [<a href="https://doi.org/10.1145/2047196.2047247">DOI:10.1145/2047196.2047247</a>] are even capable of using computer vision to take existing charts and re-design them to be more accessible and easily read by humans.</p>
</div>
<div class="col-sm-5">
<p><img src='images/revision-pie.png'></img></p>
</div>
</div>
<!---
Add these sections:
## Chart Colours
## Designing Good Charts
!-->
<!-- # Other -->
<!-- Charts and plots are typically used for comparing datasets, plotting raw data or for visualising mathematical expressions. There are many, many different types of charts/plot that serve wildly different purposes. -->
<!-- For help choosing which chart to use you might consider using these resources: -->
<!-- - [Financial Times' Visual Vocabulary](http://ft-interactive.github.io/visual-vocabulary/) -->
<!-- - [Visualising Data: Chart Directory](http://chartmaker.visualisingdata.com/) -->
<!-- We've chosen to split our charts up using a similar hierarchy to the FT's Visual Vocabulary. -->
<!-- ### Comparison / Ranking / Magnitude -->
<!-- -->
<!-- <div class="row"> -->
<!-- <div class="col-md-6"> -->
<!-- <span><a href="charts_barcharts.html">Barcharts [tutorial]</a> are very flexible visualisations that allow viewers to quickly compare the relative magnitude/ranking of multiple categories of data. By using grouped or stacked barcharts it is also possible to compare subcategories within each category.</span> -->
<!-- <br> -->
<!-- <strong>Required Data:</strong> -->
<!-- <ul> -->
<!-- <li>Categories: For instance, class of animal e.g. mammal or reptile</li> -->
<!-- <li>Values: For instance, number of animals of each class</li> -->
<!-- </ul> -->
<!-- </div> -->
<!-- <div class="col-md-4 vcenter"> -->
<!-- ```{r echo=FALSE} -->
<!-- library("highcharter") -->
<!-- library("tidyverse") -->
<!-- my_data <- tribble( -->
<!-- ~category, ~subcategory, ~value, -->
<!-- "Mammal", "human", 3, -->
<!-- "Mammal", "non-human", 4, -->
<!-- "Reptile", "snake", 6, -->
<!-- "Reptile", "iguana", 8 -->
<!-- ) -->
<!-- my_data %>% -->
<!-- hchart( -->
<!-- type = "bar", -->
<!-- hcaes( -->
<!-- x = category, -->
<!-- y = value -->
<!-- ) -->
<!-- ) %>% -->
<!-- hc_size(width = "300px", height = "300px") -->
<!-- ``` -->
<!-- </div> -->
<!-- </div> -->
<!-- <br> -->
<!-- -->
<!-- -->
<!-- <div class="row"> -->
<!-- <div class="col-md-6"> -->
<!-- <span><a href="charts_piecharts.html">Piecharts [tutorial]</a> are useful visualisations for breaking down observations into a number of categories, the totals of which sum to 100% of the data. Piecharts are fairly widely panned as poor options for data with many categorisations, it is always possible to replace a piechart with a barchart.</span> -->
<!-- <br> -->
<!-- <strong>Required Data:</strong> -->
<!-- <ul> -->
<!-- <li>Categories: For instance, species of animal e.g. human or iguana</li> -->
<!-- <li>Values: For instance, number of animals of each species</li> -->
<!-- </ul> -->
<!-- </div> -->
<!-- <div class="col-md-4 vcenter"> -->
<!-- ```{r echo=FALSE} -->
<!-- library("highcharter") -->
<!-- library("tidyverse") -->
<!-- my_data <- tribble( -->
<!-- ~category, ~value, -->
<!-- "human", 3, -->
<!-- "non-human", 4, -->
<!-- "snake", 6, -->
<!-- "iguana", 8 -->
<!-- ) -->
<!-- my_data %>% -->
<!-- hchart( -->
<!-- type = "pie", -->
<!-- hcaes( -->
<!-- x = category, -->
<!-- y = value -->
<!-- ) -->
<!-- ) %>% -->
<!-- hc_plotOptions(pie = list(dataLabels = list(enabled = FALSE))) %>% -->
<!-- hc_size(width = "300px", height = "300px") -->
<!-- ``` -->
<!-- </div> -->
<!-- </div> -->
<!-- -->
<!-- ### Correlation -->
<!-- -->
<!-- <div class="row"> -->
<!-- <div class="col-md-6"> -->
<!-- <span><a href="charts_scatterplots.html">Scatterplots [tutorial]</a> are very simple visualisations that allow viewers to compare the correlation between two variables, typically between multiple groups of data. Scatterplots may also include trendlines for comparison purposes, however the inclusion of error bars complicates the chart sufficiently to be counted as a separate type of chart.</span> -->
<!-- <br> -->
<!-- <strong>Required Data:</strong> -->
<!-- <ul> -->
<!-- <li>x coordinates: traditionally this is the independent variable, for instance the year a measurement is taken</li> -->
<!-- <li>y coordinates: traditionally this is the dependent variable, for instance the value of a measurement in a specific year</li> -->
<!-- </ul> -->
<!-- </div> -->
<!-- <div class="col-md-4 vcenter"> -->
<!-- ```{r echo=FALSE} -->
<!-- library("tidyverse") -->
<!-- library("gapminder") -->
<!-- library("highcharter") -->
<!-- gapminder %>% -->
<!-- group_by(continent, year) %>% -->
<!-- summarise(median.life.exp = median(lifeExp)) %>% -->
<!-- hchart(type = "scatter", -->
<!-- hcaes(x = year, y = median.life.exp, group = continent)) %>% -->
<!-- hc_size(width = "300px", height = "300px") -->
<!-- ``` -->
<!-- </div> -->
<!-- </div> -->
<!-- -->
<!-- ### Distribution -->
<!-- We don't currently have any tutorials for creating these types of charts, please consider making a [pull request on GitHub](https://github.com/ox-it/OxfordIDN_charts). -->
</div>
</div>
</div>
</div> <!-- articleBandContent -->
</div> <!-- pageContent -->
<div id="rStudioFooter" class="band full">
<div class="bandContent">
<h4><a href="http://oxshef.io" target="_blank" style="color:#fff;font-weight:bold">OxShef</a></h4>
<div id="logos">
<!--<a href="https://twitter.com/rstudio" class="footerLogo twitter"></a>!-->
<a href="https://github.com/ox-it/OxfordIDN_charts" class="footerLogo gitHub"></a>
<!--<a href="https://www.linkedin.com/company/rstudio-inc" class="footerLogo linkedIn"></a>
<a href="https://www.facebook.com/pages/RStudio-Inc/267733656584415" Class="footerLogo facebook"></a>-->
</div>
</div>
</div>
<!-- bizible -->
<script type="text/javascript" src="//cdn.bizible.com/scripts/bizible.js" async=""></script>
</div>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
</body>
</html>