WEBVTT NOTE Introduction 00:00:00.110 --> 00:00:02.705 Welcome! My name is Lukas, and today 00:00:02.706 --> 00:00:05.090 we will use gnuplot to draw graphs 00:00:05.160 --> 00:00:07.147 and organise the work in Emacs, 00:00:07.148 --> 00:00:09.010 a text editor, using Org mode. 00:00:09.210 --> 00:00:11.066 That lets us keep data, 00:00:11.067 --> 00:00:13.850 code and explanation in one document 00:00:13.880 --> 00:00:16.278 and build figures we can understand, 00:00:16.279 --> 00:00:17.380 revise and share. 00:00:20.520 --> 00:00:22.275 A figure may need to be corrected 00:00:22.276 --> 00:00:24.340 months later or rebuilt by someone else. 00:00:24.920 --> 00:00:26.757 That raises two questions: 00:00:26.758 --> 00:00:28.799 will our tools still serve us, 00:00:28.800 --> 00:00:30.005 and will someone 00:00:30.006 --> 00:00:31.919 understand how we use them? NOTE ROOT: Robust, Open, Ongoing and Time-tested 00:00:31.920 --> 00:00:34.945 I've developed two frameworks around those 00:00:34.946 --> 00:00:37.620 questions: ROOT for technology choices 00:00:38.040 --> 00:00:40.220 and SHAPE for workflows. 00:00:40.410 --> 00:00:42.581 ROOT concerns the tools, 00:00:42.582 --> 00:00:44.839 so that is where we start. 00:00:44.840 --> 00:00:46.964 The name stands for Robust, 00:00:46.965 --> 00:00:49.239 Open, Ongoing and Time-tested. 00:00:49.240 --> 00:00:52.055 These criteria help us assess whether we 00:00:52.056 --> 00:00:54.940 can inspect failures, understand and reuse 00:00:55.130 --> 00:00:57.666 the technology, keep using and adapting 00:00:57.667 --> 00:01:00.140 it, and draw on established experience. 00:01:00.310 --> 00:01:02.269 For gnuplot, readable scripts, 00:01:02.270 --> 00:01:04.236 continuing development and decades 00:01:04.237 --> 00:01:06.259 of use give us reasons to choose it. NOTE SHAPE: Structure, Harmonise, Automate, Propagate, Evaluate 00:01:06.260 --> 00:01:08.324 SHAPE concerns how we organise 00:01:08.325 --> 00:01:10.189 the work around those tools. 00:01:10.190 --> 00:01:12.763 It brings together five principles: 00:01:12.764 --> 00:01:15.479 structure stages, harmonise handovers, 00:01:15.480 --> 00:01:18.905 automate actions, propagate provenance, 00:01:18.906 --> 00:01:20.959 and evaluate explicitly. 00:01:20.960 --> 00:01:23.561 We look at this next because a dependable 00:01:23.562 --> 00:01:25.419 tool still needs clear inputs, 00:01:25.420 --> 00:01:26.425 agreed meanings, 00:01:26.426 --> 00:01:28.199 recorded decisions and checks. 00:01:28.200 --> 00:01:31.000 These principles give us things to look 00:01:31.001 --> 00:01:33.799 for when we watch the practical example. NOTE The dataset 00:01:33.800 --> 00:01:35.687 For that example, we will use 00:01:35.688 --> 00:01:37.699 a teaching dataset of passengers 00:01:37.700 --> 00:01:39.947 and crew aboard the Titanic, 00:01:39.948 --> 00:01:41.419 which sank in 1912. 00:01:41.420 --> 00:01:44.003 It records class or crew membership, 00:01:44.004 --> 00:01:45.539 sex, age and survival. 00:01:45.540 --> 00:01:48.083 This lets us ask a simple question: 00:01:48.084 --> 00:01:50.979 crew had more survivors than first class, 00:01:50.980 --> 00:01:54.069 but did they have a higher survival rate? 00:01:54.070 --> 00:01:55.988 We'll explore that question 00:01:55.989 --> 00:01:57.289 in an Org notebook, 00:01:57.290 --> 00:01:59.050 using gnuplot to draw 00:01:59.051 --> 00:02:00.889 and revise the figures. 00:02:00.890 --> 00:02:01.966 So our route is: 00:02:01.967 --> 00:02:03.740 introduce the tool criteria, 00:02:03.990 --> 00:02:06.008 establish the workflow principles, 00:02:06.009 --> 00:02:08.199 then put both into practice with data. NOTE Org Notebook 00:02:08.200 --> 00:02:10.078 Let's switch to our Org notebook 00:02:10.079 --> 00:02:12.069 in Emacs and start the live coding. 00:02:12.070 --> 00:02:14.058 I'll change a little code, run it 00:02:14.059 --> 00:02:16.279 and we'll look at the result together. 00:02:16.280 --> 00:02:17.829 The notebook keeps data, 00:02:17.830 --> 00:02:19.750 code and pictures in one place. 00:02:19.800 --> 00:02:22.907 First, let's open the raw CSV, 00:02:22.908 --> 00:02:24.209 the raw data. 00:02:24.210 --> 00:02:26.719 We'll turn it into a small table 00:02:26.720 --> 00:02:28.999 and build our plot from there. 00:02:29.000 --> 00:02:30.259 Our question is: 00:02:30.260 --> 00:02:32.571 did crew have a better chance 00:02:32.572 --> 00:02:35.730 of surviving than first-class passengers? 00:02:36.670 --> 00:02:39.715 Each row is one person here; survival 00:02:39.716 --> 00:02:42.759 is one for survived and zero for died. 00:02:42.760 --> 00:02:45.069 There are 2,207 people 00:02:45.070 --> 00:02:47.580 in this teaching dataset, 00:02:47.770 --> 00:02:50.272 and that's our SHAPE structure: 00:02:50.273 --> 00:02:53.399 a question and a route through the work. 00:02:53.400 --> 00:02:56.549 Next, we let AWK count the groups. 00:02:56.550 --> 00:02:58.786 Let's turn all those rows 00:02:58.787 --> 00:03:00.849 into four useful totals. 00:03:00.850 --> 00:03:03.157 We'll run this AWK block and look 00:03:03.158 --> 00:03:05.940 at the table it puts straight underneath. 00:03:06.680 --> 00:03:10.139 The commas tell AWK where each field ends. 00:03:10.140 --> 00:03:11.299 We skip the header, 00:03:11.300 --> 00:03:14.151 use the first field to identify the group 00:03:14.152 --> 00:03:16.459 and count one person for each row. 00:03:16.460 --> 00:03:18.779 Then we add the fourth field. 00:03:18.780 --> 00:03:20.752 Because it's zero or one, 00:03:20.753 --> 00:03:23.179 that sum gives us the survivors. 00:03:23.180 --> 00:03:25.243 Subtract survivors from everyone 00:03:25.244 --> 00:03:27.370 aboard and we have the deaths too. 00:03:28.200 --> 00:03:29.424 The last loop puts 00:03:29.425 --> 00:03:31.229 the groups in a fixed order. 00:03:31.230 --> 00:03:33.300 There we go: four rows 00:03:33.301 --> 00:03:35.549 with the numbers we need. 00:03:35.550 --> 00:03:37.729 This is our SHAPE handover: 00:03:37.730 --> 00:03:40.919 a small table with clear column meanings. 00:03:40.920 --> 00:03:44.040 For now, it's just an AWK result. 00:03:44.140 --> 00:03:45.946 But next, we'll add the name 00:03:45.947 --> 00:03:48.500 and plotting lines around the same table. NOTE Making our first plot 00:03:49.000 --> 00:03:50.478 Now let's make our first 00:03:50.479 --> 00:03:51.719 plot from this table. 00:03:51.720 --> 00:03:54.099 We'll add its name and plotting lines, 00:03:54.100 --> 00:03:55.706 run the plot and then put a link 00:03:55.707 --> 00:03:57.410 to the saved picture underneath it. 00:03:58.280 --> 00:04:00.240 The name is demo-class-counts, 00:04:00.241 --> 00:04:02.580 so we can use this table again later. 00:04:03.320 --> 00:04:06.422 `ind:1` takes the group names from the first 00:04:06.423 --> 00:04:09.380 column, `and deps:(3)` picks the survivors. 00:04:10.040 --> 00:04:13.109 I run `org-plot/gnuplot` inside the table. 00:04:13.110 --> 00:04:15.739 That writes our SVG file. 00:04:15.740 --> 00:04:19.009 To show it here, I add a file link below 00:04:19.010 --> 00:04:21.879 the table and refresh inline images. 00:04:21.880 --> 00:04:24.119 There are our four bars. 00:04:24.120 --> 00:04:26.675 Keeping that table and picture together 00:04:26.676 --> 00:04:29.229 makes the SHAPE handover easy to follow. 00:04:29.230 --> 00:04:32.559 Crew is slightly ahead of first class. 00:04:32.560 --> 00:04:34.217 Next, let's check how many 00:04:34.218 --> 00:04:36.119 people each group started with. 00:04:36.120 --> 00:04:39.859 Before we read too much into those bars, 00:04:39.860 --> 00:04:43.610 let's try column 2: everyone aboard. 00:04:43.620 --> 00:04:45.024 I change `deps:(3)` 00:04:45.025 --> 00:04:47.130 to `deps:(2)` and plot again. 00:04:48.680 --> 00:04:50.169 Crew had 890 people. 00:04:50.170 --> 00:04:53.499 First class had 324. 00:04:53.500 --> 00:04:56.095 Similar survivor counts came 00:04:56.096 --> 00:04:58.959 from very different group sizes. 00:04:58.960 --> 00:05:01.419 I put `deps:(3)` back and redraw. NOTE Using a Gnuplot block 00:05:01.420 --> 00:05:04.281 Next, we use a Gnuplot block so we 00:05:04.282 --> 00:05:06.979 can develop the figure ourselves. 00:05:06.980 --> 00:05:09.404 Now let's move from the table's plot 00:05:09.405 --> 00:05:11.959 instructions to a Gnuplot source block. 00:05:11.960 --> 00:05:13.588 Those plot lines were 00:05:13.589 --> 00:05:15.289 handy for a quick look. 00:05:15.290 --> 00:05:17.717 Next, we calculate percentages, 00:05:17.718 --> 00:05:20.599 reuse a style and draw several series. 00:05:20.600 --> 00:05:22.902 A source block gives us one place 00:05:22.903 --> 00:05:25.069 to read and edit those commands. 00:05:25.070 --> 00:05:27.500 We'll keep the same table 00:05:27.501 --> 00:05:29.467 and the same SVG file. 00:05:29.468 --> 00:05:32.100 The `:var` header supplies our named table. 00:05:32.600 --> 00:05:34.804 `:file` says where the picture goes, 00:05:34.805 --> 00:05:36.619 and `term` chooses the format. 00:05:36.620 --> 00:05:38.519 With the file-result 00:05:38.520 --> 00:05:40.689 settings we've prepared, 00:05:40.690 --> 00:05:43.021 Babel adds or updates the result 00:05:43.022 --> 00:05:44.999 link below the block for us. 00:05:45.000 --> 00:05:47.109 That's the automation part of SHAPE: 00:05:47.110 --> 00:05:49.474 we can rerun one recipe and keep 00:05:49.475 --> 00:05:51.479 its result together with it. 00:05:51.480 --> 00:05:55.419 Let's start with just plot data using 3. 00:05:55.420 --> 00:05:58.430 Run the block and we get four points: 00:05:58.431 --> 00:06:00.490 the survivor counts again. 00:06:00.920 --> 00:06:03.110 We'll keep building in this block. NOTE Group names 00:06:03.290 --> 00:06:06.100 Next, let's put the group names back. 00:06:07.080 --> 00:06:08.370 Let's make those four 00:06:08.371 --> 00:06:09.659 points easier to read. 00:06:09.660 --> 00:06:11.399 We'll add the group names, 00:06:11.400 --> 00:06:13.032 leave some room at the sides 00:06:13.033 --> 00:06:14.890 and start the vertical axis at 0. 00:06:15.640 --> 00:06:17.285 In the using expression, 00:06:17.286 --> 00:06:19.259 column 0 means the row number, 00:06:19.260 --> 00:06:21.276 column 3 gives us the height 00:06:21.277 --> 00:06:23.849 and xtic(1) supplies the group names. 00:06:23.850 --> 00:06:26.919 notitle removes the automatic legend. 00:06:26.920 --> 00:06:28.396 We don't need a legend 00:06:28.397 --> 00:06:30.129 for a single set of points. 00:06:30.130 --> 00:06:32.342 Run the block again and the picture 00:06:32.343 --> 00:06:33.940 updates in the same place. 00:06:34.440 --> 00:06:35.889 Now we can tell which point 00:06:35.890 --> 00:06:37.079 belongs to which group. 00:06:37.080 --> 00:06:40.420 That's the same SHAPE handover idea. 00:06:40.760 --> 00:06:42.679 Make the columns and labels clear. NOTE Adding bars 00:06:42.680 --> 00:06:44.958 Next, we'll turn them into bars 00:06:44.959 --> 00:06:47.380 and give the chart a bit of style. 00:06:49.000 --> 00:06:51.209 Let's turn these points into filled bars, 00:06:51.210 --> 00:06:52.410 then give the chart 00:06:52.411 --> 00:06:53.850 a title and clear units. 00:06:54.280 --> 00:06:56.299 We'll put the appearance settings 00:06:56.300 --> 00:06:58.199 in a small style block above it. 00:06:58.200 --> 00:06:59.709 `boxwidth` controls the width. 00:06:59.710 --> 00:07:02.480 The `fill` setting colours the bars, and 00:07:02.481 --> 00:07:05.249 the `linetype` setting gives us our blue. 00:07:05.250 --> 00:07:07.711 The plot block keeps the title and the 00:07:07.712 --> 00:07:09.920 label saying we're counting people. 00:07:09.960 --> 00:07:12.116 The little Noweb reference pulls 00:07:12.117 --> 00:07:14.599 in the style whenever we run the plot. 00:07:14.600 --> 00:07:17.286 So after changing the style, I run 00:07:17.287 --> 00:07:20.279 the plot again and see the result here. 00:07:20.280 --> 00:07:23.479 That's another bit of SHAPE automation. 00:07:23.480 --> 00:07:25.479 Reuse one definition. 00:07:25.480 --> 00:07:28.219 Same four values, much easier to read. NOTE Tidying up 00:07:28.220 --> 00:07:30.570 Let's tidy up the frame next. 00:07:31.560 --> 00:07:33.131 Before we add more data, 00:07:33.132 --> 00:07:35.710 let's tidy up the borders and tick marks. 00:07:36.120 --> 00:07:38.054 We'll keep the bottom and left 00:07:38.055 --> 00:07:39.739 edges and add a light grid. 00:07:39.740 --> 00:07:42.779 Each border has a value: 00:07:42.780 --> 00:07:45.095 Bottom is 1, left is 2, 00:07:45.096 --> 00:07:47.409 top is 4 and right is 8. 00:07:47.410 --> 00:07:49.479 Add the sides you want. 00:07:49.480 --> 00:07:52.981 1 + 2 gives 3, so set border 00:07:52.982 --> 00:07:55.879 3 keeps bottom and left. 00:07:55.880 --> 00:07:58.402 The ticks have separate settings: 00:07:58.403 --> 00:08:01.369 nomirror removes their copies at the top 00:08:01.370 --> 00:08:03.090 and right, and out points 00:08:03.091 --> 00:08:05.669 the remaining ticks away from the bars. 00:08:05.670 --> 00:08:09.140 The grid goes behind the data. 00:08:09.150 --> 00:08:11.029 Our small SHAPE check here is 00:08:11.030 --> 00:08:13.159 whether the scale is easy to read. NOTE Additional series 00:08:13.160 --> 00:08:14.751 Now we are ready to bring 00:08:14.752 --> 00:08:16.649 in the people who died as well. 00:08:16.650 --> 00:08:19.369 Let's show survivors and deaths together. 00:08:19.370 --> 00:08:20.957 We use two bars per group, 00:08:20.958 --> 00:08:23.309 with a legend so we can tell them apart. 00:08:23.310 --> 00:08:25.388 We switch to clustered histograms 00:08:25.389 --> 00:08:27.650 and give the plot command two series. 00:08:27.820 --> 00:08:29.690 One takes the survivor column; 00:08:29.691 --> 00:08:31.319 the other takes the deaths. 00:08:31.320 --> 00:08:32.820 Blue means survived 00:08:32.821 --> 00:08:34.920 and the pale bars mean died. 00:08:35.130 --> 00:08:36.659 Putting the bars side by side 00:08:36.660 --> 00:08:38.629 makes it easy to compare the two 00:08:38.630 --> 00:08:40.239 outcomes within each group. 00:08:40.240 --> 00:08:42.391 I'll keep the legend above the chart 00:08:42.392 --> 00:08:44.020 so it leaves the data clear. 00:08:44.600 --> 00:08:46.441 We can already see a different 00:08:46.442 --> 00:08:47.629 story in each group. NOTE Stacking outcomes 00:08:47.630 --> 00:08:49.776 So next we'll stack these 00:08:49.777 --> 00:08:52.169 same bars to show the totals. 00:08:52.170 --> 00:08:54.771 Let's stack those two outcomes and see 00:08:54.772 --> 00:08:57.039 what happens to the overall shape. 00:08:57.040 --> 00:08:59.102 We only need to change the histogram 00:08:59.103 --> 00:09:01.220 layout and update the title and units. 00:09:01.880 --> 00:09:04.679 Now each full bar is everyone aboard: 00:09:04.680 --> 00:09:06.123 the blue part is survivors 00:09:06.124 --> 00:09:07.620 and the pale part is deaths. 00:09:08.110 --> 00:09:10.335 A useful SHAPE check is that those 00:09:10.336 --> 00:09:12.370 parts add up to the group total. 00:09:13.000 --> 00:09:15.399 Look at crew compared with first class. 00:09:15.400 --> 00:09:17.468 The blue parts are quite similar, 00:09:17.469 --> 00:09:19.719 but the full crew bar is much taller. 00:09:19.720 --> 00:09:23.719 Crew had 890 people; first class had 324. 00:09:23.720 --> 00:09:26.354 So a similar number of survivors came 00:09:26.355 --> 00:09:28.849 from very different starting groups. NOTE Percentages 00:09:28.850 --> 00:09:31.863 Next we'll put each group on a percentage 00:09:31.864 --> 00:09:34.589 scale to make that comparison clearer. 00:09:34.590 --> 00:09:36.223 Now let's turn those 00:09:36.224 --> 00:09:38.090 counts into percentages. 00:09:38.110 --> 00:09:40.241 We write one small rate function 00:09:40.242 --> 00:09:42.759 and use it for both parts of the stack. 00:09:42.760 --> 00:09:45.817 The function takes a count, divides it by 00:09:45.818 --> 00:09:48.729 the number aboard and multiplies by 100. 00:09:48.730 --> 00:09:50.244 Writing it once saves us 00:09:50.245 --> 00:09:51.879 repeating that calculation. 00:09:51.880 --> 00:09:55.110 That's the automate-actions idea in SHAPE. 00:09:55.290 --> 00:09:57.110 Then we use it for the survivor 00:09:57.111 --> 00:09:58.759 column and the deaths column, 00:09:58.760 --> 00:10:01.430 and set the axis from 0 to 100. 00:10:01.610 --> 00:10:03.537 Run the block and every stack 00:10:03.538 --> 00:10:05.079 reaches the same height. 00:10:05.080 --> 00:10:06.912 The blue part now takes up much 00:10:06.913 --> 00:10:08.629 more of first class than crew. 00:10:08.630 --> 00:10:10.680 That's the difference we couldn't 00:10:10.681 --> 00:10:12.549 see from survivor counts alone. 00:10:12.550 --> 00:10:15.309 Let's keep just those survival rates next. 00:10:15.310 --> 00:10:17.637 Let's make the answer easier to pick 00:10:17.638 --> 00:10:20.089 out by showing only the survival rates. 00:10:20.090 --> 00:10:22.143 We'll go back to simple bars 00:10:22.144 --> 00:10:24.480 and keep the full 0 to 100 scale. 00:10:25.390 --> 00:10:27.590 We remove the histogram settings 00:10:27.591 --> 00:10:29.389 and the two-outcome legend. 00:10:29.390 --> 00:10:31.459 The rate function stays and we use 00:10:31.460 --> 00:10:33.469 it to calculate each bar's height. 00:10:33.470 --> 00:10:35.872 I also put percent signs on the tick 00:10:35.873 --> 00:10:38.599 labels so the units are clear at a glance. 00:10:38.600 --> 00:10:41.709 First class is highest; crew is lowest. 00:10:41.710 --> 00:10:44.349 We've changed from asking how many 00:10:44.350 --> 00:10:47.289 survived to asking what share survived. 00:10:47.290 --> 00:10:49.114 That's our SHAPE check: 00:10:49.115 --> 00:10:51.850 does the measure match our question? NOTE Leaving out a group 00:10:52.600 --> 00:10:54.562 Next I'll show you how to leave out 00:10:54.563 --> 00:10:56.469 a group without changing the table. 00:10:56.470 --> 00:10:58.254 Let's look at passengers 00:10:58.255 --> 00:10:59.539 only for a moment. 00:10:59.540 --> 00:11:01.223 We'll hide crew in this view 00:11:01.224 --> 00:11:03.140 and leave the source table alone. 00:11:04.360 --> 00:11:05.352 Inside using, 00:11:05.353 --> 00:11:07.479 we check the name in column 1. 00:11:07.480 --> 00:11:11.879 If it's Crew, we return 1 divided by 0. 00:11:11.880 --> 00:11:13.619 Gnuplot treats that as 00:11:13.620 --> 00:11:16.039 an undefined value and skips it. 00:11:16.040 --> 00:11:17.293 For the other rows, 00:11:17.294 --> 00:11:19.109 we keep the rate calculation. 00:11:19.110 --> 00:11:21.275 We also adjust the horizontal range 00:11:21.276 --> 00:11:23.200 and say passengers in the title. 00:11:23.250 --> 00:11:25.428 That's a small SHAPE check: 00:11:25.429 --> 00:11:28.539 the title should tell us who's included. 00:11:28.540 --> 00:11:31.118 There are our three passenger classes 00:11:31.119 --> 00:11:33.289 with their original percentages. 00:11:33.290 --> 00:11:35.483 Next we'll bring crew back and write 00:11:35.484 --> 00:11:37.439 the actual values above the bars. 00:11:37.440 --> 00:11:39.837 That way nobody has to estimate 00:11:39.838 --> 00:11:41.709 the values from the axis. 00:11:41.710 --> 00:11:44.009 We restore the original range 00:11:44.010 --> 00:11:45.916 and add another use of the same table 00:11:45.917 --> 00:11:46.919 to the plot command. 00:11:46.920 --> 00:11:49.706 This time it supplies text 00:11:49.707 --> 00:11:52.079 at each bar's position. 00:11:52.080 --> 00:11:54.507 sprintf formats the number to one 00:11:54.508 --> 00:11:57.220 decimal place and adds a percent sign. 00:11:57.720 --> 00:12:00.366 Both the bar and its label use our rate 00:12:00.367 --> 00:12:02.880 function, so they agree automatically. 00:12:04.040 --> 00:12:06.259 That's SHAPE automation saving 00:12:06.260 --> 00:12:08.549 us from copying numbers by hand. 00:12:08.550 --> 00:12:11.354 Now we can read about 62% 00:12:11.355 --> 00:12:15.129 for first class and 23.7% for crew. NOTE Digging into the details 00:12:15.130 --> 00:12:17.295 Let's see what those group 00:12:17.296 --> 00:12:19.300 averages might be hiding. 00:12:19.960 --> 00:12:21.437 Let's split that comparison 00:12:21.438 --> 00:12:22.439 into women and men. 00:12:22.440 --> 00:12:24.680 We'll connect a second named table 00:12:24.681 --> 00:12:26.280 to the same Gnuplot block 00:12:26.470 --> 00:12:29.079 and draw the two rates beside each other. 00:12:29.080 --> 00:12:32.113 I add `sex=demo-class-sex` 00:12:32.114 --> 00:12:33.820 to the `:var` header. 00:12:33.980 --> 00:12:35.799 That table comes from the same CSV 00:12:35.800 --> 00:12:38.877 but keeps separate counts for the recorded 00:12:38.878 --> 00:12:41.309 sex categories including children. 00:12:41.310 --> 00:12:42.948 Same SHAPE handover: 00:12:42.949 --> 00:12:45.989 we need to know what each column means. 00:12:45.990 --> 00:12:47.978 For each series we divide 00:12:47.979 --> 00:12:50.959 its survivors by its own number aboard. 00:12:50.960 --> 00:12:53.719 Run it and we get two bars per group. 00:12:53.720 --> 00:12:56.459 Women have higher survival rates 00:12:56.460 --> 00:12:58.119 in every group here. 00:12:58.120 --> 00:13:00.318 So the overall group rate leaves 00:13:00.319 --> 00:13:02.049 out quite a bit of detail. 00:13:02.050 --> 00:13:04.258 Next, we'll try a different way 00:13:04.259 --> 00:13:06.189 to show the same comparison. 00:13:06.190 --> 00:13:08.617 Let's keep those two calculations 00:13:08.618 --> 00:13:10.829 and try points instead of bars. 00:13:10.830 --> 00:13:12.963 It's a quick way to see how much 00:13:12.964 --> 00:13:15.549 the choice of chart changes the picture. 00:13:15.550 --> 00:13:18.389 We remove the histogram settings and use 00:13:18.390 --> 00:13:21.160 a circle for women and a square for men. 00:13:21.350 --> 00:13:24.789 Each pair sits at the same group position. 00:13:24.790 --> 00:13:27.298 Our SHAPE check is whether this view 00:13:27.299 --> 00:13:29.739 makes the comparison easier to read. 00:13:29.740 --> 00:13:31.650 The shapes help us tell them 00:13:31.651 --> 00:13:33.559 apart as well as the colours. 00:13:33.560 --> 00:13:35.281 We can still see the gap 00:13:35.282 --> 00:13:36.589 within every group, 00:13:36.590 --> 00:13:38.754 and the common percentage scale 00:13:38.755 --> 00:13:40.580 lets us compare groups too. 00:13:40.920 --> 00:13:42.058 That's another view 00:13:42.059 --> 00:13:44.279 from the same table and the same block. NOTE Overall group rates 00:13:44.280 --> 00:13:47.486 Let's finish with the overall 00:13:47.487 --> 00:13:49.409 group rates again. 00:13:49.410 --> 00:13:51.346 We'll bring back the four labelled 00:13:51.347 --> 00:13:52.839 bars and add a source line, 00:13:52.840 --> 00:13:54.578 so the saved figure makes 00:13:54.579 --> 00:13:56.449 sense outside this notebook. 00:13:56.450 --> 00:13:58.414 We remove the women and men 00:13:58.415 --> 00:14:00.519 table from the variable header 00:14:00.520 --> 00:14:02.099 and use our original 00:14:02.100 --> 00:14:03.979 class-counts table again. 00:14:03.980 --> 00:14:05.790 Then we add the dataset 00:14:05.791 --> 00:14:07.300 version and its DOI. 00:14:07.640 --> 00:14:09.820 That's the provenance part of SHAPE: 00:14:10.010 --> 00:14:11.643 someone can trace this 00:14:11.644 --> 00:14:13.559 picture back to its source. 00:14:13.560 --> 00:14:16.080 The subgroup comparison showed that there 00:14:16.081 --> 00:14:18.359 are differences inside each group too, 00:14:18.360 --> 00:14:21.319 so we'll be careful about what we claim. 00:14:21.320 --> 00:14:23.148 These are the overall 00:14:23.149 --> 00:14:25.060 rates in this snapshot. NOTE Checking 00:14:26.120 --> 00:14:28.010 Next let's check the total 00:14:28.011 --> 00:14:29.199 before we export. 00:14:29.200 --> 00:14:32.160 We'll also check that the shared style 00:14:32.161 --> 00:14:34.969 still updates when we rerun the plot. 00:14:34.970 --> 00:14:38.015 The stars in the stats ranges tell Gnuplot 00:14:38.016 --> 00:14:40.919 to use all the data for this calculation. 00:14:40.920 --> 00:14:43.053 Otherwise our percentage axis 00:14:43.054 --> 00:14:45.399 would leave out counts above 100. 00:14:45.400 --> 00:14:48.409 This keeps the chart at 0 to 100, 00:14:48.410 --> 00:14:50.805 while stats adds up all 00:14:50.806 --> 00:14:53.399 four survivor counts: 711. 00:14:53.400 --> 00:14:54.797 We use that result 00:14:54.798 --> 00:14:56.929 in a small label so the total 00:14:56.930 --> 00:14:59.575 comes from the table rather than from 00:14:59.576 --> 00:15:02.219 a number we've typed into the picture. 00:15:02.220 --> 00:15:04.793 Now I'll briefly change the shared 00:15:04.794 --> 00:15:06.999 colour and run the plot again. 00:15:07.000 --> 00:15:09.709 There's the colour change. 00:15:09.710 --> 00:15:12.589 Restore it and rerun: we're back to blue. 00:15:12.590 --> 00:15:14.590 Our style connection works, 00:15:14.591 --> 00:15:17.589 and the total agrees with the input check. 00:15:17.590 --> 00:15:20.437 That's SHAPE's evaluate-explicitly idea, 00:15:20.438 --> 00:15:22.660 with a concrete number to check. NOTE Saving as PDF 00:15:24.110 --> 00:15:25.862 Next, we save the finished 00:15:25.863 --> 00:15:27.159 figure as a PDF too. 00:15:27.160 --> 00:15:29.659 We already have the SVG, 00:15:29.660 --> 00:15:32.120 so we'll change the output options 00:15:32.121 --> 00:15:34.369 and keep the plot code as it is. 00:15:34.370 --> 00:15:36.280 In the header, I change 00:15:36.281 --> 00:15:38.350 the filename to end in PDF 00:15:38.390 --> 00:15:41.189 and choose pdfcairo as the terminal. 00:15:41.190 --> 00:15:43.550 Run the block, open the file, 00:15:43.551 --> 00:15:45.360 and there's our figure. 00:15:45.960 --> 00:15:47.475 Then I restore the SVG 00:15:47.476 --> 00:15:49.319 options for the inline view. 00:15:49.320 --> 00:15:51.489 Keeping the recipe, 00:15:51.490 --> 00:15:53.759 source and export together carries 00:15:53.760 --> 00:15:55.639 our SHAPE provenance forward. 00:15:55.640 --> 00:15:58.388 We can now answer our original question: 00:15:58.389 --> 00:16:00.600 crew had slightly more survivors, 00:16:00.810 --> 00:16:02.836 but a much lower survival rate 00:16:02.837 --> 00:16:05.060 than first class in this snapshot. 00:16:05.400 --> 00:16:07.658 We've got the data, the calculation 00:16:07.659 --> 00:16:09.540 and the saved result together. NOTE What else can Gnuplot do? 00:16:11.240 --> 00:16:13.290 Now let's spend a few minutes 00:16:13.291 --> 00:16:15.749 looking at what else Gnuplot can do. 00:16:15.750 --> 00:16:17.929 Let's start with three views together. 00:16:17.930 --> 00:16:19.213 I'll show the prepared 00:16:19.214 --> 00:16:20.329 code and the result, 00:16:20.330 --> 00:16:22.050 and we'll just look at what 00:16:22.051 --> 00:16:23.340 the picture tells us. 00:16:23.510 --> 00:16:25.753 On the left, the stacks show 00:16:25.754 --> 00:16:27.919 how many people were aboard. 00:16:27.920 --> 00:16:29.060 In the middle, 00:16:29.061 --> 00:16:31.719 the percentages change the ranking. 00:16:31.720 --> 00:16:34.088 On the right, the connected dots 00:16:34.089 --> 00:16:36.960 compare women and men within each group. 00:16:36.990 --> 00:16:39.020 Putting them together helps us 00:16:39.021 --> 00:16:40.919 see how the questions relate. 00:16:40.920 --> 00:16:43.485 Each panel has a clear job 00:16:43.486 --> 00:16:46.050 just like our SHAPE stages. 00:16:46.250 --> 00:16:48.322 Next, let's look at who made 00:16:48.323 --> 00:16:50.110 up the population aboard. 00:16:51.400 --> 00:16:54.039 This one is about the size of each group. 00:16:54.040 --> 00:16:56.406 Crew makes up about 40% 00:16:56.407 --> 00:16:58.970 and third class about 32%. 00:17:00.200 --> 00:17:03.229 First and second class make up the rest. 00:17:03.230 --> 00:17:05.575 The names and percentages sit right 00:17:05.576 --> 00:17:07.919 in the picture so it's easy to read. 00:17:07.920 --> 00:17:11.316 These slices describe who was aboard; the 00:17:11.317 --> 00:17:14.469 survival rates are a separate question. 00:17:14.470 --> 00:17:16.743 Next, we'll try showing 00:17:16.744 --> 00:17:19.489 several measures in one view. 00:17:19.490 --> 00:17:21.860 So let's try a spider plot. 00:17:22.360 --> 00:17:25.051 It gives each group a shape by placing 00:17:25.052 --> 00:17:27.189 several measures on the spokes. 00:17:27.190 --> 00:17:30.309 Each outline is one group and every 00:17:30.310 --> 00:17:32.909 spoke uses a percentage scale. 00:17:32.910 --> 00:17:34.509 You can follow an outline 00:17:34.510 --> 00:17:37.020 around to see that group's profile 00:17:37.021 --> 00:17:39.459 or compare groups along one spoke. 00:17:39.460 --> 00:17:41.220 The overall shape can 00:17:41.221 --> 00:17:43.220 help us spot differences. 00:17:43.640 --> 00:17:45.328 But the area inside it 00:17:45.329 --> 00:17:46.869 isn't a single score. 00:17:46.870 --> 00:17:49.965 Next, we'll return to class and sex 00:17:49.966 --> 00:17:52.889 and read the rates through colour. 00:17:52.890 --> 00:17:55.659 So let's look at the heatmap. 00:17:55.660 --> 00:17:58.055 The groups run down the side, 00:17:58.056 --> 00:18:01.250 and women and men have separate columns. 00:18:01.360 --> 00:18:03.589 The colour gives us a quick impression, 00:18:03.590 --> 00:18:05.988 and the text keeps the percentages 00:18:05.989 --> 00:18:07.289 and counts visible. 00:18:07.290 --> 00:18:10.865 Look at crew: the women's rate comes from 00:18:10.866 --> 00:18:14.440 23 people, while the men's comes from 867. 00:18:14.550 --> 00:18:16.488 Now let's bring age into 00:18:16.489 --> 00:18:18.039 the picture as well. 00:18:18.040 --> 00:18:21.080 Here we have a bubble 00:18:21.790 --> 00:18:26.059 for each age band and class or crew group. 00:18:26.060 --> 00:18:28.379 Colour shows survival rate, 00:18:28.380 --> 00:18:30.533 while bubble area shows how 00:18:30.534 --> 00:18:32.839 many people are in that group. 00:18:32.840 --> 00:18:34.615 So a tiny bright bubble means 00:18:34.616 --> 00:18:36.450 a high rate among a few people. 00:18:36.520 --> 00:18:39.128 This view uses the 2,205 00:18:39.129 --> 00:18:42.049 people whose ages are known. 00:18:42.050 --> 00:18:45.445 For the last plot we will turn those same 00:18:45.446 --> 00:18:48.759 age groups into a three-dimensional view. 00:18:48.760 --> 00:18:51.161 For this last plot, let's look 00:18:51.162 --> 00:18:53.950 at the same age groups as a skyline. 00:18:54.680 --> 00:18:55.643 The columns make 00:18:55.644 --> 00:18:57.399 the population sizes stand out. 00:18:57.400 --> 00:18:59.813 Height shows people aboard 00:18:59.814 --> 00:19:03.119 and colour still shows survival rate. 00:19:03.120 --> 00:19:05.115 The large groups of young adults 00:19:05.116 --> 00:19:06.869 now look like tall buildings. 00:19:06.870 --> 00:19:09.557 It's the same data we just saw as bubbles, 00:19:09.558 --> 00:19:12.119 but with a different way of drawing them. 00:19:12.120 --> 00:19:13.922 We can still trace it back 00:19:13.923 --> 00:19:16.259 which is our SHAPE provenance idea. 00:19:16.260 --> 00:19:17.511 That's a good place 00:19:17.512 --> 00:19:18.949 to finish the examples, 00:19:18.950 --> 00:19:21.787 and I'll leave you with the sources 00:19:21.788 --> 00:19:24.309 and somewhere to keep exploring. 00:19:24.310 --> 00:19:27.422 But before we finish, let me point you to 00:19:27.423 --> 00:19:30.459 the sources and the rest of the material. 00:19:30.460 --> 00:19:32.690 The DOI links here take you 00:19:32.691 --> 00:19:35.159 to the dataset, ROOT and SHAPE, 00:19:35.160 --> 00:19:37.115 so you can follow up on the data 00:19:37.116 --> 00:19:39.069 and the ideas behind the session. 00:19:39.070 --> 00:19:41.254 If you'd like a deeper dive into 00:19:41.255 --> 00:19:43.239 the open educational resource, 00:19:43.240 --> 00:19:45.779 visit https://gnuplot.emaix.org. 00:19:45.780 --> 00:19:48.579 The QR code takes you there too. 00:19:48.580 --> 00:19:50.519 You will find the lessons, 00:19:50.520 --> 00:19:52.648 code and datasets, ready for you 00:19:52.649 --> 00:19:54.389 to try things out yourself. 00:19:54.390 --> 00:19:58.020 Happy plotting!