Skip to main content

Chapter 12: Visualizing the narrative

Listen in Dr. Leith’s voice

Chapter 11 ended with a single tidy table, analysis, a little over thirty-five thousand rows wide. That table is a complete and faithful record of the chat study’s data, and it is almost impossible to read. Nobody can scroll thirty-five thousand rows and come away knowing whether gaming chat runs longer than non-gaming chat, or when in the day the channels are busiest. The numbers are all present. The pattern is not visible.

A figure is the instrument that makes the pattern visible. It takes a column of numbers too long to hold in the mind and turns it into a shape the eye can read at a glance: a line that rises, a bar that towers over its neighbors, a distribution that leans hard to one side. This chapter builds three such figures from the analysis table. Each one answers a question the study has been carrying since its prospectus, and each one is a different kind of chart, chosen to fit a different kind of question.

The chapter’s title is a claim about what that work is for. A figure does not merely display data. A well-made figure carries an argument: it shows the reader what the analyst found and why it matters. Visualization is not decoration applied after the analysis. It is part of the analysis, and it is where the study’s narrative first becomes something other people can see.

The grammar of graphics

The figures in this chapter are built with ggplot2, the R package that has become the standard tool for statistical graphics (Wickham, 2016). What makes ggplot2 worth learning is not a catalog of chart types. It is a single idea, borrowed from a book by Leland Wilkinson called The Grammar of Graphics (Wilkinson, 2005): that every statistical graphic can be described as the same small set of parts, combined in different ways.

Three parts do most of the work. The first is the data, the table being shown. The second is a set of aesthetic mappings, which say how columns of that table correspond to visual properties of the plot: this column to the horizontal position, that column to the vertical position, a third to color. The third is a geometry, the kind of mark used to draw the data, a line or a bar or a point. Choose the data, map the columns to aesthetics, pick a geometry, and a plot is specified.

In code the three parts sit in a recognizable skeleton:

ggplot(data, aes(x = ..., y = ...)) +
  geom_line()

ggplot() names the data and, inside aes(), the aesthetic mappings. geom_line() is the geometry. The + is ggplot2’s way of stacking layers: each piece is added to the plot, and a figure is assembled by composition rather than written all at once. Changing one part changes the figure without disturbing the rest. Swap geom_line() for geom_col() and the same data is drawn as bars. That is the payoff of a grammar. A handful of interchangeable parts covers an enormous range of figures, and learning the parts is learning all of them at once.

The three figures that follow are three settings of the same grammar.

NoteIn the course, the R Companion writes these blocks

The R Companion, the course’s extension for VS Code, writes code blocks like this chapter’s from a menu: run AURA: Write R code and look under R3 Describe.

Step by step:

Counting before plotting

Before any figure, the study says what is in the table in numbers, because a figure summarizes a distribution and a reader needs to know what was summarized. Two kinds of summary cover most variables, and which one applies is the level of measurement from Chapter 8.

A categorical variable is summarized by a frequency table: each category and how many cases fall in it. Both chapters so far have used count() for this, and pretty_table(), from the course package, v2v, formats the result for a report. Every table carries a label that says which variable it shows, because a column of numbers under n tells a reader nothing on its own.

library(tidyverse)
library(v2v)

analysis <- read_rds("data/twitch_analysis.RDS")
streams  <- v2v::twitch_streams()

analysis %>%
  count(is_gaming, name = "messages") %>%
  v2v::pretty_table()
is_gaming messages
FALSE 3,457
TRUE 31,309
NA 501

The table says three things at a glance: most of the sample is gaming chat, the non-gaming group is about a tenth of it, and 501 messages have no label at all, the two channels Chapter 11 could not classify. The imbalance matters for every comparison that follows.

A continuous variable is summarized by three numbers. The mean is the average: the sum of the values divided by how many there are. The median is the middle value when the values are sorted, so half the cases sit below it and half above. The standard deviation measures spread: roughly, how far a typical value sits from the mean, in the variable’s own units. A standard deviation of 38 characters says that message lengths typically land a few dozen characters away from the average. Report all three for every continuous variable, and whenever the mean and the median disagree by much, say so, because the gap between them is the first sign that a distribution is lopsided. The histogram section below shows what that gap looks like and why it happens.

A line for change over time

The first question is about viewership. Across the collection week, how did the audience for these fifty channels move, and how was it split across the games being played?

When the horizontal axis is time and the vertical axis is a quantity that rises and falls, the natural geometry is the line chart. A line connects one moment to the next, and the eye reads the climb and the drop as a single continuous motion. That is what makes a line right for change over time and wrong for unordered categories: it implies that the points are in sequence and that the space between them is real.

The data needs shaping first, and the shaping takes three dplyr steps the course has not taught: the stream snapshots are grouped into six-hour buckets, the long tail of games is collapsed so that only the five most common categories keep their names and the rest become “Other,” and the viewer counts are summed within each bucket. The course package does that work and returns the table ready to plot, and prints the dplyr it stands for the first time you call it:

viewers_over_time <- twitch_viewers_over_time()

viewers_over_time %>%
  count(category)

The count shows the six categories a line will be drawn for: the five most common games and “Other.”

With the data in shape, the figure itself is short. The aesthetic mappings send the time bucket to the x-axis, the summed viewers to the y-axis, and the game category to color, so each category gets its own line:

ggplot(viewers_over_time, aes(x = six_hour, y = total_viewers, color = category)) +
  geom_line(linewidth = 0.9) +
  labs(
    title = "Concurrent viewers by game category",
    x = "Date (UTC, six-hour buckets)",
    y = "Total viewers in bucket",
    color = "Category"
  ) +
  v2v::scale_color_v2v() +
  v2v::theme_v2v()

The last line is worth a note. v2v::theme_v2v() applies a single consistent visual theme, the fonts, spacing, and gridlines of a publication-ready figure, in one call. Every figure in this chapter ends with it, so the three look like members of one set rather than three unrelated charts.

A figure that exists only on the screen is not yet part of the study. Save it to a file from the code that made it, so that the file is rebuilt whenever the figure changes and never falls out of date. The chart blocks of the R Companion (the AURA Lab R Companion icon on VS Code’s left edge) do this for you: after you select Run it on the notice that appears, the saved chart opens in its own VS Code tab. By hand, it is two lines:

dir.create("figures", showWarnings = FALSE)   # make the folder if it is missing
ggsave("figures/fig-viewers-by-game.png", width = 8, height = 5, dpi = 300)

ggsave() writes the most recent plot to the path given, at the size and resolution stated. The figures/ folder is where the portfolio scaffold put it. A figure saved by hand, through a menu or a screenshot, is a figure that will silently stay old the next time the data changes.

A line chart with one line per game category across November 18 to 24, 2018. The Other category towers over the rest, spiking above 20 million viewers several times, while Art, Fortnite, Hearthstone, Just Chatting, and Pokemon stay low near the axis.

Total concurrent viewers across the focal fifty channels, summed within six-hour UTC buckets and split by game category, over the November 2018 collection week.

The figure has an obvious headline. The line that dominates the plot is “Other,” the catch-all holding every game outside the top five, and it spikes far above any named category. That fact can be read two ways, and a careful analyst holds both. One reading is substantive: the viewership in this corpus is genuinely spread across a long tail of games, with no single title commanding the audience the way a casual observer might expect. The other reading is a caution about the chart’s own choices: lumping more than fifty categories into one bucket all but guarantees that bucket will be the largest, so part of what the figure shows is an artifact of where the line between “named” and “Other” was drawn. There is also a plain design cost. Because “Other” is so large, the five named lines are pressed into the bottom of the plot, and the comparison a reader might most want, how Fortnite moved against Just Chatting across the week, is hard to make. A dominant series can crowd out the rest, and noticing that is part of reading a figure honestly.

A bar for counts

The second question is about timing. The chat data spans a little under six days; across the hours of the day, when are the channels busiest?

Hour of day is not a continuous sweep the way a date is. It is a set of twenty-four discrete categories, and the thing being measured for each is a simple count of messages. For counts across discrete categories, the natural geometry is the bar chart: one bar per category, its height the count, the bars sitting side by side so the eye can compare them.

The data is one short pipeline. The hour is pulled out of each message’s timestamp, and the messages are counted within each hour:

chat_by_hour <- analysis %>%
  mutate(hour = hour(ts)) %>%
  count(hour, name = "messages")

ggplot(chat_by_hour, aes(x = hour, y = messages)) +
  geom_col(fill = "#2f7d8a") +
  labs(
    title = "Chat volume by hour of day",
    x = "Hour of day (UTC)",
    y = "Messages in sample"
  ) +
  v2v::theme_v2v()

geom_col() is the geometry that draws a bar whose height is a value already computed, which is what count() produced.

A bar chart of message counts for each of the 24 hours of the day in UTC. Bars are tallest around 13:00, 16:00, and 17:00, reaching roughly 2,200 messages, and shortest around 03:00, near 830 messages.

Total chat messages in the sample by hour of day in UTC, across the collection window.

The figure shows a clear daily pulse. Chat is busiest through the UTC midday and afternoon, peaking at 13:00 with 2,201 messages, and quietest in the small hours, bottoming out at 03:00 with 833, a swing of well over two to one between the loudest hour and the quietest. The shape is not mysterious. Twitch’s audience in 2018 was concentrated in the Americas and Europe, and the UTC midday and afternoon are the waking, screen-facing hours across that span, while 03:00 UTC is the middle of the night for most of it. One choice shapes this figure and is disclosed in its axis label: the hours are in UTC, not in any viewer’s local time, so the peak at 13:00 is morning in Chicago and evening in Berlin. The point worth taking is less the particular peak than what the bar chart does: it takes twenty-four numbers and makes a rhythm visible in one glance, which is exactly the job a bar chart is for.

A histogram for shape

The third question is the study’s central one. The chat study set out to compare gaming and non-gaming channels through message length. So: how long is a chat message, and does the answer depend on the kind of channel?

This question is not about a total or a trend. It is about a distribution, the shape of how a single variable’s values spread out, where they cluster and where they thin. The geometry for a distribution is the histogram. A histogram slices the range of a numeric variable into equal intervals, called bins, and draws a bar for each showing how many values fall inside it. The result is a picture of the variable’s shape.

The figure overlays two histograms, one for gaming channels and one for non-gaming, so the shapes can be compared directly. Messages with no gaming label, the unmatched rows Chapter 11 set aside, are dropped first, and message lengths are capped at 120 characters for the view:

msglen <- analysis %>%
  filter(!is.na(is_gaming)) %>%
  mutate(length_shown = pmin(message_length, 120))

ggplot(msglen, aes(x = length_shown, y = after_stat(density * width),
                   fill = is_gaming)) +
  geom_histogram(binwidth = 5, position = "identity", alpha = 0.55) +
  labs(
    title = "Message length, gaming versus non-gaming channels",
    x = "Message length (characters, capped at 120)",
    y = "Share of the group's messages",
    fill = "Gaming channel"
  ) +
  v2v::scale_fill_v2v() +
  v2v::theme_v2v()

Three choices in that code shape the figure and all have to be disclosed. The y = after_stat(density * width) draws each bar as a share of its own group’s messages rather than a count, so the bars of each group add up to 1. Gaming channels carry about nine messages in ten here, so by count the non-gaming shape would barely show. The binwidth = 5 sets each bar to cover five characters; a wider bin smooths the shape and a narrower one roughens it, and the number is a judgment the analyst makes and reports. The pmin(message_length, 120) caps the displayed length at 120 characters, so every message longer than that lands in the final bar. Twitch’s real message limit is far higher, 500 characters, so that last bar is a genuine pile-up of long messages compressed into one place. Capping keeps the bulk of the distribution legible instead of stretched thin by a few very long outliers, but a cap that is not announced is a quiet distortion. The axis label says “capped at 120” for exactly that reason.

Two overlaid histograms of message length. Both are heavily right-skewed, with most messages short, under 20 characters, and a long thin tail toward longer messages. Each group is drawn as shares of its own messages, so the two shapes sit at comparable heights: a little over half of each group's messages are under 20 characters. A pile-up bar appears at the 120-character cap, higher for non-gaming channels, about 5 percent of their messages against about 3 percent for gaming.

Overlaid histograms of message length for gaming and non-gaming channels, bin width five characters, lengths capped at 120.

The figure shows, first, a shape both groups share. Each distribution is heavily right-skewed: a tall stack of very short messages at the left, then a long thin tail trailing off to the right. Twitch chat is mostly brief, a word or an emote, with a minority of longer messages stretching the range. This is the most important thing the histogram reveals, and it is invisible in any single summary number.

It matters because of what the summary numbers say. The descriptive statistics for the two groups, the kind of table v2v::pretty_table() formats cleanly, set the comparison up:

msglen %>%
  group_by(is_gaming) %>%
  summarize(
    n      = sum(!is.na(message_length)),
    mean   = mean(message_length, na.rm = TRUE),
    median = median(message_length, na.rm = TRUE),
    sd     = sd(message_length, na.rm = TRUE),
    .groups = "drop"
  ) %>%
  v2v::pretty_table()
is_gaming n mean median sd
FALSE 3,457 33.70 16 60.68
TRUE 31,305 28.49 17 38.47

The gaming row counts 31,305 rather than the 31,309 messages that came from gaming channels, because four messages in the corpus have no text at all and therefore no length. Counting rows where the statistics skip four of them would make the n column describe a different set of messages from the columns beside it.

Read the mean column and a story jumps out: non-gaming messages, the FALSE row, average 33.70 characters against 28.49 for gaming messages. Non-gaming chat looks meaningfully longer. Now read the median column, the length of the exactly-middle message in each group, and the story collapses: 16 characters for non-gaming, 17 for gaming, all but identical, and pointing the other way. The typical message is the same length in both kinds of channel.

The histogram explains how both things can be true at once. The mean is sensitive to a long tail in a way the median is not: a relatively small number of very long messages pulls an average upward while leaving the middle value untouched. The non-gaming group has the heavier tail, which its much larger standard deviation, 60.68 against 38.47, records directly. So the gap in means is real arithmetic, but it is the work of the tail, not of the typical message. Lean only on the mean and you would report that non-gaming chat is longer. The picture, and the median beside it, show that the everyday message is the same and the difference lives in the extremes.

NoteWrite it up: descriptive statistics

Messages on non-gaming channels (n = 3,457) averaged 33.70 characters (SD = 60.68, Mdn = 16), and messages on gaming channels (n = 31,305) averaged 28.49 characters (SD = 38.47, Mdn = 17).

Part In the model
Group size n for each group
Center M, the mean, written as “averaged”
Spread SD, the standard deviation
The typical case Mdn, the median, because message length is skewed

Plain sentence: a typical message runs about 16 or 17 characters on either kind of channel; the averages differ because a few very long messages pull the non-gaming average up.

Common mistake: reporting the means alone for a skewed variable, which makes the groups look more different than their typical messages are.

This is what it means to treat descriptive statistics as a visual setup rather than a verdict. A mean is one number standing in for thousands, and which thousands it stands in for is something only the distribution can show. It also leaves a precise question for the next chapter. There is a gap of about five characters between the two means. Is that gap a real difference between gaming and non-gaming channels, or the kind of wobble that any two samples would show? A figure can frame that question. It cannot answer it.

Effect size reporting with every comparison. A good figure conveys the pattern in the data without distortion, and descriptive reporting adds a further requirement on top of that: every figure that displays a comparison must include the effect size of that comparison. A bar chart showing that one group scored higher than another is not a scientific claim; it is a visual impression. The effect size quantifies the magnitude of that difference in a scale-invariant unit. Cohen’s d reports how many standard deviations apart two group means are; Cramer’s V reports the strength of association between two categorical variables after accounting for marginal distributions. These values let future researchers use your descriptives as inputs for their power analyses, closing the cumulative science loop that Chapter 4 opened. The case for making the practice routine begins from the standing effect sizes hold in the evidence itself:

“Effect sizes are the most important outcome of empirical studies.”

Lakens (2013, p. 1)

Lakens (2013) argues that routine effect size reporting would improve meta-analyses in communication research; for your own work, ask what practical barriers stand in the way of adopting the convention in a field where effect sizes are rarely reported in standard write-ups.

A cross-tabulation

The histogram compared a continuous variable across two groups. The other comparison a study usually needs is between two categorical variables, and the table for it is a cross-tabulation: one variable down the rows, the other across the columns, and in each cell the count of cases that fall in both. The chat study has such a pair ready to hand. Whether a channel is gaming is one categorical variable. Whether a message contains an at-mention, a @ addressed to someone, is another, computed from the message text, and it is the manifest half of the message-target variable from Chapter 8. The question is whether the two go together: is addressed chat more or less common on gaming channels?

mentions <- analysis %>%
  filter(!is.na(is_gaming), !is.na(message)) %>%
  mutate(has_mention = str_detect(message, "@"))

mentions %>%
  count(is_gaming, has_mention, name = "messages") %>%
  v2v::pretty_table()
is_gaming has_mention messages
FALSE FALSE 3,220
FALSE TRUE 237
TRUE FALSE 28,235
TRUE TRUE 3,070

Read within each group, because the groups are so different in size that raw counts mislead. On non-gaming channels, 237 of 3,457 messages carry an at-mention, about 7 percent. On gaming channels, 3,070 of 31,305 do, about 10 percent. Addressed messages are a small minority in both kinds of channel, and a little more common in gaming chat. The table is labeled so a reader can tell the rows from the columns, and it reads the same way every cross-tabulation does: the counts say what is there, the percentages within a group make the groups comparable, and whether a three-point gap is more than sampling noise is a question for Chapter 13, where this exact table meets the chi-square test.

What the table does not show is as important as what it does. It says nothing about why addressed chat is rarer on non-gaming channels, and it cannot, because the non-gaming group is five channels and any one of them could be driving the figure. A cross-tabulation describes an association. It never explains one.

Three figures and two tables are built. Before they are finished, they have to be made readable, and not only by the analyst who made them. Every one of them also gets two or three sentences of plain interpretation in the write-up: what it shows, and what it cannot show. The second half is the one students skip. The histogram shows that the typical message is the same length in both kinds of channel; it cannot show whether the five-character gap in means would survive a different sample. Saying both is the habit.

The first duty is color. The viewer-count figure tells its categories apart by color, and the histogram tells its two groups apart by color, and roughly one in twelve men has a form of color-vision deficiency that makes some color pairs, red against green most notoriously, hard or impossible to distinguish. A figure whose meaning rests on color alone is a figure that some readers cannot read. There are two defenses, and good practice uses both. Choose a colorblind-safe palette, a set of colors picked to stay distinct across the common kinds of color blindness. And do not let color carry the message by itself: separate the lines by more than hue, or split groups into their own panels, so the figure still works in grayscale.

The second duty is the alt text, a short written description of the figure attached to it in the document’s source. A reader using a screen reader cannot see the figure at all; the alt text is what they get instead, and a figure with none is, to them, simply missing. Good alt text is not the caption repeated. It states what kind of chart the figure is, what is on each axis, and what the figure shows, the takeaway, in a sentence or two. Each figure in this chapter carries one. In a Quarto document the alt text is written into the figure’s fig-alt attribute, and writing it is not an afterthought. Under R3 Describe, the R Companion’s Write R code writes the line chart (Line chart over time) and the histogram (Histogram comparing two groups); its Bar chart draws the ten most-streamed games instead. Each chart block leaves an alt = line marked YOUR TURN inside labs() and, in a Quarto file, a #| fig-alt: line at the top of the chunk; the sentence in both is yours to write. Being forced to say in one sentence what a figure shows is a good test of whether the figure shows anything at all.

A figure that is honest about its choices, legible without color, and described for readers who cannot see it is a figure that does its job for everyone. That is the standard a publication-quality figure is held to, and the three built here are meant to meet it.

Diagnostics behind each figure. A figure is a claim about a distribution, and the diagnostic is whether you are allowed to make it. For every figure that feeds a test, report three things with the check shown. The shape of the variable: the histogram above shows message length is heavily right-skewed in both groups, with medians of 16 and 17 against means of 33.70 and 28.49, and skew that strong means the mean is a poor summary of a typical message. The outliers and where they sit: 1,047 messages, about 3 percent, lie beyond the 120-character cap, stretched out to 501 characters, and the cap is what keeps them from flattening the figure. And whether the assumptions of the test you are heading toward look reasonable: a t-test on these groups assumes similar spread, and the standard deviations of 60.68 and 38.47 say the spread is not similar, which is why Chapter 13 runs the Welch version; it also assumes roughly normal data within groups or a sample large enough not to need it, and with tens of thousands of messages the second condition holds even though the first plainly does not. Show the numbers behind each statement, in the chapter’s own tables or a short summarize() call, rather than asserting them. A figure with no diagnostic is a picture; a figure with one is evidence.

Reporting conventions. For every group comparison in a visualization, report the effect size in the figure caption or a companion table. For group means: Cohen’s d with a 95% confidence interval. For cross-tabulations: Cramer’s V. For correlations: r and its CI. effectsize::cohens_d(), effectsize::cramers_v(), and cor.test() compute these, and Chapter 13 shows each call. For two figures in your current analysis, report the effect size you would include in the caption; if one effect is small by Cohen’s (1988) conventions, consider what that implies for the interpretive claim you planned to make.

Looking ahead

The histogram left a precise question on the table. The means of the two groups differ by about five characters, and the distributions behind those means are skewed, overlapping, and built from very different numbers of messages. Whether that five-character gap is a real difference or only sampling noise is not something the eye can settle. Chapter 13 takes it up. It is the inference chapter, where the study moves from describing what the sample looks like to testing what the difference is likely to mean.

References

Wickham, H. (2016). ggplot2: Elegant graphics for data analysis (2nd ed.). Springer. https://doi.org/10.1007/978-3-319-24277-4

Wilkinson, L. (2005). The grammar of graphics (2nd ed.). Springer. https://doi.org/10.1007/0-387-28695-0

Graduate readings

Lakens, D. (2013). Calculating and reporting effect sizes to facilitate cumulative science: A practical primer for t-tests and ANOVAs. Frontiers in Psychology, 4, 863. https://doi.org/10.3389/fpsyg.2013.00863