Skip to Content
Course content

157: Practice Exercise: Building a Multi-Panel Dashboard Report

Click on the "Edit" button in the top corner of the screen to edit your slide content.

How do I actually arrange different plots into a grid without it becoming a mess?

If you've tried using par(mfrow = ...) or grid.arrange(), you know it can feel clunky. I almost always use the patchwork package now. It treats ggplot objects like mathematical expressions, which is honestly a game-changer for building dashboards. You can use + to put plots side-by-side and / to stack them on top of each other.

library(ggplot2)
library(patchwork)

# Let's imagine we're tracking e-commerce sales
p1 <- ggplot(sales_data, aes(x = date, y = revenue)) + 
      geom_line(color = "steelblue") + 
      labs(title = "Daily Revenue")

p2 <- ggplot(sales_data, aes(x = category, y = revenue)) + 
      geom_col(fill = "darkseagreen") + 
      labs(title = "Revenue by Category")

p3 <- ggplot(sales_data, aes(x = region, y = orders)) + 
      geom_bar(fill = "indianred") + 
      labs(title = "Orders by Region")

# This is where the magic happens:
# p1 on top, p2 and p3 side-by-side underneath
dashboard <- p1 / (p2 + p3)
dashboard

How do I handle titles and labels so they don't look redundant?

One thing that makes a dashboard look "amateur" is repeating the same axis labels on every single panel. If every plot says "Revenue (USD)" on the Y-axis, it's just visual noise. I usually strip the axis titles from the individual plots and instead use plot_annotation() to give the entire dashboard one clear, overarching title and subtitle.

Here is how I'd clean that up:

# Remove axis labels from the individual plots
p1 <- p1 + labs(x = NULL, y = NULL)
p2 <- p2 + labs(x = NULL, y = NULL)
p3 <- p3 + labs(x = NULL, y = NULL)

# Add the global dashboard heading
dashboard <- (p1 / (p2 + p3)) + 
  plot_annotation(
    title = 'Q3 Executive Sales Performance',
    subtitle = 'Analysis of regional growth and product category trends',
    caption = 'Data sourced from Internal Warehouse API'
  )

What's the best way to make the panels feel like a cohesive report?

The secret is consistency in theme and layout ratios. If one plot is a tiny square and the other is a giant rectangle, the eye doesn't know where to land. You can use plot_layout() to specify exactly how much space each plot should take. I also highly recommend defining a single theme object and applying it to all plots—this ensures your fonts, grid lines, and margins are identical across the board.

Try this approach to balance the visual weight:

# Define a consistent look
my_theme <- theme_minimal() + 
            theme(plot.title = element_text(face = "bold", size = 12))

# Apply theme and set the top plot to take up 60% of the height
dashboard <- (p1 + my_theme) / (p2 + my_theme + p3 + my_theme) + 
             plot_layout(heights = c(2, 1))

dashboard



📋 Practical Task

Exercise: Build a Regional Healthcare Utilization Dashboard

You have been provided with a dataset health_stats containing three columns: clinic_id, patient_count, wait_time, and region. Your goal is to create a professional multi-panel report using patchwork.

Requirements:

  • Plot A: A boxplot of wait_time grouped by region.
  • Plot B: A bar chart showing the total patient_count per region.
  • Plot C: A scatter plot of patient_count vs wait_time.
  • Layout: Arrange the plots so that the scatter plot (Plot C) occupies the top row (full width), and the boxplot and bar chart (Plots A and B) are side-by-side on the bottom row.
  • Styling: Remove all individual X and Y axis titles. Add a global title "Regional Healthcare Efficiency Report" and a subtitle "Analyzing patient throughput and wait times across districts" using plot_annotation().
  • Balance: Use plot_layout() to ensure the top plot is twice as tall as the bottom row.
Rating
0 0

There are no comments for now.

to be the first to leave a comment.