Skip to course content
Free R statistics course

Statistical Data Analytics with R

Unit 12.02: One comparison, three views

The table, the test and the chart must describe the same comparison at the same grain — and the chart usually shows what the difference hides.

One comparison, three views

A common failure in reports is that the table summarises one thing, the test compares another, and the chart shows a third. A reader who notices loses confidence in all three; a reader who does not is misled.

The chart's job is not to repeat the table. It is to show what the summary cannot: the overlap between groups, the shape of each distribution, the points that do not fit.

A significant difference between two heavily overlapping distributions is a real finding and a modest one, and only the chart conveys that second part.

This block produces the table, the test and the chart for one comparison.

suppressPackageStartupMessages({library(dplyr); library(ggplot2)})
set.seed(902)
d <- data.frame(arm = rep(c("A", "B"), each = 300),
                value = c(rnorm(300, 50, 9), rnorm(300, 53, 9)))

tab <- d |> group_by(arm) |>
  summarise(n = n(), mean = round(mean(value), 2),
            sd = round(sd(value), 2),
            se = round(sd(value)/sqrt(n()), 3), .groups = "drop")
print(tab)

tt <- t.test(value ~ arm, data = d)
diff_ba <- as.numeric(diff(tt$estimate))          # estimate is c(A, B)
cat("\nDifference (B - A):", round(diff_ba, 2),
    " 95% CI [", round(-tt$conf.int[2], 2), ",",
    round(-tt$conf.int[1], 2), "]\n\n")

# The chart must show the same comparison the table and the test report.
p <- ggplot(d, aes(arm, value)) +
  geom_boxplot(width = 0.5) +
  labs(x = NULL, y = "Value", title = "B scores higher, with heavily overlapping distributions")
f <- file.path(tempdir(), "capstone.png")
ggsave(f, p, width = 5, height = 3.5, dpi = 150)

cat("Table, test and chart all describe the same comparison at the same grain.\n")
cat("The boxplot shows the overlap the difference alone hides -- the group SDs\n")
cat("are", tab$sd[1], "and", tab$sd[2], "against a difference of",
    round(diff_ba, 2), ".\n")
cat("Chart written:", file.size(f), "bytes\n")

The table gives n = 300 per arm, means of 49.3 and 52.9, and standard deviations of 9.72 and 9.36. The test reports a difference of 3.65 with an interval from 2.12 to 5.18 — clearly non-zero. The boxplot then shows the part the difference alone hides: the group SDs are around 9.5 against a difference of 3.65, so the two distributions overlap heavily. Real, reliable, and small relative to individual variation.

The mistake this prevents

The mistake is a chart that shows only the two means with error bars. It repeats the table and conceals the overlap, which is the thing a reader most needs to see.

Takeaway

Make the table, the test and the chart describe the same comparison at the same grain. Choose a chart that shows the distributions, not just the summary, and state the group SDs beside the difference.