Describing Lab

S24 · Chapter 12 · MC 451 Research Methods in Mass Media

Dr. Alex Leith

Today’s Agenda

  • A summary table before any picture
  • Three figures on your own variables
  • Labels, color, and alt text
  • Saving figures the paper can use

Today’s Job

Describing Data, 75 points, due this week

  • Tuesday you watched me build three figures
  • Today you build three on yours, with me in the room
    • Everything you make lands in your Results section
  • Work in a .qmd in your project, not the console

Get stuck out loud. That is what the room is for.

Where You Should Be Starting

  • Your project opens and your .qmd renders
  • You have a tidy analysis table from the wrangling assignment
  • You know which one variable the paper is about
  • You know which column splits it into groups

If any of those is missing, say so now and we fix it first.

Loading and Looking

library(tidyverse)
library(v2v)

analysis <- readRDS("data/analysis.rds")

glimpse(analysis)

glimpse() prints every column with its type and its first few values. Before you plot anything, look at what you actually have.

A Summary Table First

analysis %>%
  group_by(is_gaming) %>%
  summarise(
    n      = n(),
    mean   = mean(message_length, na.rm = TRUE),
    median = median(message_length, na.rm = TRUE),
    sd     = sd(message_length, na.rm = TRUE),
    .groups = "drop"
  )

Swap in your grouping column and your variable. Read the mean against the median before you draw anything.

Your Turn

  • Do your mean and median agree, or pull apart?
  • If they pull apart, in which direction?
  • What does that predict about the shape?
  • Which single number would you put in an abstract, and why?

Figure One, the Shape

ggplot(analysis, aes(x = message_length)) +
  geom_histogram(binwidth = 5) +
  labs(x = "Message length (characters)", y = "Messages") +
  v2v::theme_v2v()

One variable, one histogram. Change binwidth and watch the shape change, which is why the number has to be reported rather than hidden.

Reading Your Own Histogram

  • Where is the tall stack? That is the typical case
  • Is there a long thin tail, and in which direction?
    • Right-skewed means most values small, a few very large
    • A skewed variable is why mean and median disagreed
  • If you capped the axis with pmin(), say so in the label

Figure Two, Counts by Category

analysis %>%
  count(game, name = "messages") %>%
  slice_max(messages, n = 8) %>%
  ggplot(aes(x = reorder(game, messages), y = messages)) +
  geom_col(fill = "#2f7d8a") +
  coord_flip() +
  v2v::theme_v2v()

Count, keep the top eight, sort the bars, then flip so long names are readable. Unsorted bars are much harder to compare.

Figure Three, Groups Side by Side

analysis %>%
  filter(!is.na(is_gaming)) %>%
  ggplot(aes(x = message_length, fill = is_gaming)) +
  geom_histogram(binwidth = 5, position = "identity", alpha = 0.55) +
  v2v::scale_fill_v2v() +
  v2v::theme_v2v()

position = "identity" with alpha overlays the two groups so the shapes compare. Stacked bars would hide exactly the comparison you want.

Labels Are Not Optional

last_plot() +
  labs(
    title = "Message length by channel type",
    x = "Message length (characters, capped at 120)",
    y = "Messages",
    fill = "Gaming channel"
  )

Default labels are column names, which mean nothing to a reader. Every axis gets units, and every cap gets named.

Colorblind-Safe by Default

  • Roughly one man in twelve has a color-vision deficiency
    • Red against green is notorious, and not the only pair
  • Use scale_colour_v2v() and scale_fill_v2v()
  • Do not let color carry the message alone
    • Add a linetype, or split into panels
  • If it fails in grayscale, it fails for some readers

Alt Text, Written Not Skipped

  • A screen-reader user gets the alt text instead of the figure
    • With none, the figure is simply missing
  • Alt text is not the caption repeated
  • Say the chart type, the axes, and what it shows
  • In Quarto it goes in the figure’s fig-alt attribute

Common Errors and Meanings

  • object 'analysis' not found: you never ran the load line
  • could not find function "ggplot": the tidyverse has not loaded
  • Blank gray panel: aes() names a column that does not exist
  • Error in +: a + is missing, or one is trailing
  • Everything on one bar: your x is a character, not a number

Run ?v2v::common_errors for the ones specific to this data.

Saving Figures for the Paper

ggsave(
  "figures/fig-msglen.png",
  width = 7, height = 4.5, dpi = 300
)

ggsave() writes the last plot to a file at a size and resolution you control. Fixed dimensions mean the figure looks the same everywhere.

Checkpoint

You should now have, saved in your project:

  • A grouped summary with n, mean, median, and sd
  • Three figures on theme_v2v(), all fully labeled
  • Alt text drafted for each one
  • One sentence under each figure saying what it shows
  • A .qmd that renders start to finish

Before Next Time

  • Due this week: Describing Data [R], 75 points
  • Read Chapter 13, “Making the call,” before Tuesday
  • Tuesday we answer what your figures only framed
    • Bring the summary table you built today
    • No new math to learn in advance

Questions?