Storytelling with Data Layouts

Overview

The stwd package provides block functions for building presentation-ready story layouts. Use story_designer() to interactively design layouts, then copy the generated patchwork code.

Block Functions

title_block()

Creates a large, prominent title. Supports marquee syntax for colored text.

title_block(
    "**Q4 Sales: {#E63946 Apples} Take the Lead**",
    title_size = 10
)

subtitle_block()

Adds supporting context below the title.

subtitle_block(
    "{#2A9D8F Revenue} up 15% | {#E63946 Costs} down 3%",
    subtitle_size = 10
)

text_narrative()

Creates a text panel for the “so what?” explanation.

text_narrative(
    text = "**Key insight:**
        {#E63946 Strong growth} in core markets.",
    size = 10
)

caption_block()

Adds source attribution at the bottom.

caption_block("Source: Finance Department | Q4 2024", caption_size = 6)

legend_block()

Creates an inline colored text legend instead of a traditional legend box.

legend_colors <- c("HIGH" = "#E63946", "MEDIUM" = "#808080", "LOW" = "#457B9D")

legend_block(legend_colors, halign = "right", sep = " | ")

Combining Blocks with Patchwork

Stack blocks vertically with / and set proportional heights:

df <- data.frame(x = c("A", "B", "C"), y = c(30, 50, 20))

chart <- ggplot(df, aes(x, y, fill = x)) +
    geom_col() +
    scale_fill_manual(values = c(A = "#E63946", B = "#CCCCCC", C = "#CCCCCC"),
                      guide = "none") +
    theme_minimal() +
    labs(x = NULL, y = NULL)

title_block("**{#E63946 Category A} Leads**", title_size = 12) /
subtitle_block("Year-over-year comparison", subtitle_size = 10) /
chart /
caption_block("Source: Internal Analytics") +
    plot_layout(heights = c(0.08, 0.06, 0.78, 0.08))

Adding a Narrative Panel

Place chart and narrative side by side with + and set proportional widths:

narrative <- text_narrative(
    "**Summary:**

{#E63946 Category A} leads with 50 units.",
    size = 8
)

content <- chart + narrative + plot_layout(widths = c(0.65, 0.35))

title_block("**{#E63946 Category A} Leads**", title_size = 12) /
subtitle_block("Year-over-year comparison", subtitle_size = 10) /
content /
caption_block("Source: Internal Analytics") +
    plot_layout(heights = c(0.08, 0.06, 0.78, 0.08))

Helper Functions

Function Purpose
highlight_colors() Gray out non-essential categories
theme_stwd() Clean SWD theme (horizontal grid only)

Workflow

  1. Create your ggplot chart
  2. Launch story_designer(plot = p)
  3. Adjust text, sizes, and layout in the app
  4. Copy the generated code from the Code tab
  5. Paste into your Quarto document with matching fig-width, fig-height, fig-dpi

See the Sizing Guide for details on matching dimensions.