Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 1 Small multiples, or the science and art of combining graphs Nicholas J. Cox Department of Geography Durham University, UK.

Similar presentations


Presentation on theme: "1 1 Small multiples, or the science and art of combining graphs Nicholas J. Cox Department of Geography Durham University, UK."— Presentation transcript:

1 1 1 Small multiples, or the science and art of combining graphs Nicholas J. Cox Department of Geography Durham University, UK

2 2 Small multiples Good graphics often exploit one simple design that is repeated for different parts of the data. Edward Tufte called this the use of small multiples. Well-designed small multiples are inevitably comparative, deftly multivariate, shrunken, high-density graphics…. Edward Rolf Tufte (1942–)

3 3 …in Stata In Stata, small multiples are supported for different subsets of the data with by() or over() options of many graph commands. Users can emulate this in their own programs by writing wrapper programs that call t woway or graph bar and its siblings. Otherwise, specific machinery offers repetition of a design for different variables, such as the graph matrix command.

4 4 Users can always put together their own composite graphs by saving individual graphs and then combining them using graph combine. This presentation offers further modest automation of the same design repeated for different data.

5 5 5 Original programs discussed are stripplot sparkline crossplot combineplot designplot subsetplot with cameo roles for aaplot and sepscatter. All may be installed from SSC.

6 6 What’s in a name? roseplot by any other name… A minor theme here is that definite names are needed for programs, even if kinds of graphs do not have distinct agreed names. As in advertising, a good name attracts and keeps users. As in politics, a bad name can be fatal.

7 stripplot Show me. Unofficial nickname of Missouri 7

8 stripplot stripplot started as an alternative to graph oneway in 1999, but by a mix of accident and design has morphed into an alternative to the official command dotplot. I have shown results from stripplot in previous meetings, so I will just feature here some additions to the latest incarnation. The aim is to compare univariate distributions with scope for linear or stacked dot plots, box plots and confidence intervals. We can now do side-by-side quantile plots. 8

9 As with dotplot, you can now show reference lines for means or medians – and indeed any reference level for which there is a suitable egen function. The examples here use Stata’s citytemp and auto datasets. 9

10 10

11 11

12

13

14 14 sparkline The purpose of visualization is insight, not pictures. Ben Shneiderman (1947–)

15 15 Sparklines The name “sparkline” was suggested by Edward Tufte for intense text-like graphics. Sparklines are typically simple in design, sparing of space and rich in data, but they include several quite different kinds of graph otherwise. The most common kind shows several time series stacked vertically. sparkline is a Stata implementation.

16 16 Sparklines have long been standard in several fields, including physics and chemistry (spectroscopy), seismology, climatology, ecology, archaeology and physiology (notably encephalography and cardiography). Tufte provided an memorable and evocative new name and an excellent provocative discussion. The Grunfeld data ( webuse grunfeld ) are a classic dataset in panel-based economics. Ten companies were monitored for 1935–54. They give us a simple sandbox.

17 17 What are we doing here? The problem of time series graphics Comparisons of time series are a rich and challenging area of statistical graphics. The widespread term spaghetti plot hints immediately at the difficulties. As always, we want to combine a grasp of general patterns with access to individual details. With this in mind, we look at some sparkline s of the Grunfeld dataset.

18 18

19 19

20 20

21 21 Vertical and horizontal By default sparkline stacks small graphs vertically. If several graphs are combined, it is typical to cut down on axis labels and rely on differences in shape to convey information. Horizontal stacking is also supported, which can be useful for archaeological or environmental problems focused on variations with depth or height. Here is an archaeological dataset as example.

22 22

23 23 Nightingale’s data Florence Nightingale (1820–1910) is well remembered for her nursing in the Crimean war and (within statistical science) for use of quantitative arguments. Her most celebrated dataset is often reproduced using her polar diagram, but is easier to think about as time series. Zymotic (loosely, infectious) disease mortality dominates other kinds, so much so that a square root scale helps comparison. (A logarithmic scale over-transforms here.)

24 24

25 25 Watch out: the small print does explain that we are given superimposed sectors. Each sector must be assessed as a whole, from the centre outwards. The distinct colouring of each annular sector shows only the outermost part of each sector. Source of image: http://understandinguncertainty.org/coxcombs

26 26

27 27

28 28 Would sparkline help? A sparkline display is useful to show relative shape, such as times of peaks. We see that seasonality is only part of what is being seen. The harsh winter of 1854–5 coincided with some of the hardest battles of the war, but 1855–6 was quite different. But, as often happens, no one graph dominates others here.

29 29

30 30 crossplot The scatter plot is the workhorse of statistical graphics. John McKinley Chambers (1941– )

31 31 crossplot crossplot is designed as a quick-and-easy way to combine scatter plots. The basic syntax is crossplot (yvarlist) (xvarlist) and the idea is to plot every y in yvarlist against every x in xvarlist. The use of two varlist s gives greater flexibility than does graph matrix, which produces every possible scatter plot for a single varlist.

32 32 Scatter plot matrices Scatter plot matrices are great, but they can be excessive. Their main feature is also a limitation. p variables mean p 2 plots all at once, so 10 means 100, and so forth. (The half option just controls which plots you see. )

33 33 crossplot design crossplot was developed in teaching, especially of regression, with the aim of encouraging focused comparisons. Originally (1999) crossplot was called cpyxplot, cp meaning Cartesian product, but the name was ugly, cryptic and easily forgotten. The syntax had to be as simple as possible.

34 34 crossplot examples Versions of a response variable versus a key predictor. A response variable versus versions of a key predictor. Each output versus each input. Principal components versus original variables. First, let us look at four versions of mpg versus weight in the auto dataset.

35 35

36 36 Next we look at an audiometric dataset used as a multivariate example in the Stata manuals. There are 8 response variables, 4 for left ears and 4 for right ears. Here we just focus on the 16 plots pairing left and right. Another graph could be the 4 plots comparing left and right ears at the same frequency, the diagonal here.

37 37

38 38 crossplot syntax for examples crossplot (mpg rt_mpg ln_mpg rec_mpg) weight, combine(imargin(small)) crossplot (lft*) (rght*), jitter(1)

39 39 crossplot syntax extras By default, crossplot is just calling twoway scatter followed by graph combine. It follows that recast() is available to recast to twoway line or twoway connected. crossplot has an extra sequence() option to label graphs to ease preparation of graphics for papers e.g. sequence(a b c d)

40 40 combineplot The greatest value of a picture is when it forces us to notice what we never expected to see. John Wilder Tukey (1915–2000)

41 41 combineplot combineplot is a generalisation of crossplot, more flexible and inevitably more complicated in syntax. The general problem of combining plots of similar kind reduces to a loop producing individual plots and a call to graph combine. That is bound to be a challenge to beginning users. The idea is to avoid that by encapsulating the predictable syntax within one command.

42 42 combineplot examples We will look at a series of univariate examples followed by a series of bivariate examples. A great variety is possible, as we can loop over user-written graphics commands as well as official commands.

43 43

44 44

45 45

46 46

47 47

48 48 A digression on sepscatter The last example used sepscatter, a program automating separation of data points on a scatter plot by a categorical variable. The repetition of the legend needs some kind of fix. In this and similar examples, the legend could be deleted and explaining symbols left as a task for the text caption.

49 49 sepscatter and scatter plot matrices combineplot with sepscatter meets a felt need, scatter plot matrices with categorisation of data points. Here is an example with “size” variables from the auto dataset. The diagonal scatter plots have meaning, yet are not conventional. But not every graph need be immediately publishable.

50 50

51 51

52 52 A digression on aaplot The last example used aaplot. aaplot customises automatic annotation of scatter plots with fitted regressions with text for key results. Originally, it was written following a request by my Ph.D. student Alona Armstrong.

53 53 Back to combineplot Some examples of its syntax will make clearer how it works. First look at a univariate example: combineplot mpg price weight headroom: graph box @y, over(rep78) Here we have one varlist and the syntax @y is a placeholder for the variable name.

54 54 Next look at a bivariate example: combineplot price (mpg weight length displacement): sepscatter @y @x, ytitle("Price (USD)") sep(foreign) Here we have two varlist s and the syntax elements @y and @x are placeholders for the variable names.

55 55 The two varlist s may each contain a single variable and they may be identical. When both are presented, the combination is the Cartesian product of the varlist s. Naturally, you can reach through to control the options of graph combine as well as those of the particular graph command used.

56 56 Quirk or quick? The quirky syntax of combineplot might cause some queasiness. Some might recall the obsolete for command. Confident users would (should) be happy to write their own loops, topped by graph combine, and that is fine too. The justification for combineplot is just convenience: it can be quicker than writing your own script.

57 57 designplot Real life is both complicated and short, and we make no mockery of honest adhockery. Irving John Good (1916–2009)

58 58 designplot Here more than anywhere arbitrariness of names can bite. If you have used S or S-Plus or R much, you may have come across “design plots”. But as implemented there they do not look much like the graphs you are going to see. Nor are they plots showing fitted results; nor do they imply experimental design. To understand designplot, we need to creep up on it step by step.

59 59

60 60

61 61 designplot syntax Minimal syntax specifies a response first, then one or more predictors. The predictors should in practice be categorical, meaning taking on only a small or moderate number of distinct levels (“factors”, if you like). The examples were designplot mpg rep78 designplot mpg rep78 foreign

62 62 designplot default The statistics shown are means. Given one, two, … predictors, the means are shown for all the data, each one-way breakdown, each two-way breakdown, …. designplot uses a syntax of way being 0, 1, 2, … graph dot is the default vehicle. statsby underpins calculations. In essence, we can get a multiscale breakdown. In practice, we might want to restrict what is shown.

63 63

64 64 Restricting designplot Here we restricted the scope by designplot mpg foreign rep78, maxway(1) Let us look at a different dataset. The response variable for these data on the Titanic is a binary variable survived, so its mean is the fraction survived. We restrict using maxway(2).

65 65

66 66 So we have here: the overall mean one-way breakdowns for three predictors class, adult, male two-way breakdowns for combinations class×adult, class×male, adult×male

67 67 This kind of graph is for detailed scrutiny, rather than delivering shock. Logically similar displays are often used for reporting opinion poll or electoral results.

68 68 That reminds us of… The structure echoes analysis of variance, used descriptively. Similar ideas appear in ANOVA and other literature going back to J.W. Tukey in 1977. It also echoes the little used official command grmeanby. By default, grmeanby also shows means. (Medians are allowed.) It allows one-way breakdowns only.

69 69

70 70

71 71 grmeanby In these examples, grmeanby shows different means distinctly, but that is not guaranteed. Using graph dot as a default within designplot ensures more readability, although that too has its limits.

72 72 designplot can show other statistics You can show any summarize result. In practice, you would only want to plot results sharing the same units of measurement (including none at all, as with skewness and kurtosis).

73 73

74 74 More to say… Although based on graph dot by default, designplot can be recast to graph bar or graph hbar. Reference lines in the style of grmeanby can also easily be added. Although based on summarizing single variables, what could be simpler than putting different designplot s side-by-side?

75 75

76 76 Is this just a reinvention of graph dot ? No. graph dot and its siblings are restricted in offering only one-way or two-way or three-way breakdowns given, respectively, one or two or three “factors”. designplot gives scope for saving results for separate graphing or tabulation.

77 subsetplot To clarify, add detail. Edward Rolf Tufte (1942– )

78 Graphing subsets subsetplot automates an approach discussed in Stata Journal 10: 670–681 (2010). The idea is to plot each subset separately, but with the rest of the data as a backdrop. We thus combine juxtaposing and superimposing, in the hope of getting the best of both approaches. The cost is some redundancy.

79 Superimpose or juxtapose? The principle of superimposing subsets is easy to understand. The question is whether it really works in practice. With even say 5 subsets, mentally extracting each subset and comparing with the others can be hard work. Consider a conventional grouped scatter plot and a subsetplot alternative in our final fling with the auto data.

80

81 The previous graph can be got with sepscatter mpg weight, sep(rep78) mylabel(rep78) The next graph can be got with subsetplot scatter mpg weight, by(rep78)

82

83 With an ordered (Likert) scale such as repair record rep78, self-describing marker labels can be natural and effective.

84

85 The Grunfeld data again This approach is especially suitable as another way to tackle the spaghetti problem of plotting multiple time series. Here are the invest data for different companies. If the plot seems excessively simple, then there are some bells and whistles for adding key extras.

86

87

88 How far can we go? The Grunfeld data are perhaps at the trivial end of this problem. For a stiffer challenge, here are some data for the 28 countries of the European Union on long-term unemployment. As often, a graph can be valuable in suggesting what else to plot….

89

90 90 The main players again were stripplot sparkline crossplot combineplot designplot subsetplot Our attraction to images as a source of understanding is both primal and pervasive. Stephen Jay Gould (1941–2002)


Download ppt "1 1 Small multiples, or the science and art of combining graphs Nicholas J. Cox Department of Geography Durham University, UK."

Similar presentations


Ads by Google