Published and tested 19 November 2026.
The annotation table needs the same facet column as the plot data, here panel. Each row specifies its panel, two existing category labels, a height and a descriptive label. Use that table in geom_segment() and geom_text(). The table routes the layer to the matching facet; inherit.aes = FALSE gives it its own mapping. Layer reference.
What goes wrong if the panel column is missing?
I check each bracket against the two groups in its own panel. If the same bracket turns up in another panel, the facet column is the first place I look.

panel. Both brackets appear in both facets, adding the other panel's categories to each free x scale. The 24 observations are synthetic, in arbitrary response units. This example isolates annotations repeating across facets. This article uses simulated example data.
panel in the same annotation rows. Each facet has one bracket and two categories, with all observation values unchanged. Pair A and Pair B name the compared pairs. On a narrow screen, scroll within the figure to inspect the other panel.How should I choose endpoints with free x scales?
Match the complete displayed category values, such as Start.A and End.A, and verify that both occur in the annotation's panel. Explicit factor levels keep their order. Missing or misspelled endpoints can add unintended categories. The example checks endpoint membership and category counts. See facet_wrap.
This example places bars at category centers. For dodged bars, calculate and check the offset of each bar before placing brackets.
Does this calculate significance or repair ggsignif itself?
It draws supplied brackets using ggplot2 only. The ggsignif manual example also uses an annotation data frame for precise facet placement. This tutorial uses ggplot2 directly. For statistical annotations, supply labels from an appropriate, verified analysis.
How do I reproduce the figures?
Run Rscript --vanilla example.R in an empty output folder with ggplot2 installed. Tested with R 4.5.3 and ggplot2 4.0.4. It creates 24 deterministic simulated observations and two annotation rows. Checks confirm two brackets per facet before, one after, and unchanged response values. PNG files are 1400 × 900 pixels at approximately 300 PPI; the PDF page is approximately 118.53 × 76.2 mm. For submission, adjust these example dimensions to the journal requirements and inspect the fonts in the final PDF.
These are the code, data and result files used in this article. Choose a file below to run the example or compare your results.
- example.RComplete example code to run on your computer.
- synthetic.csvThe input data used in the example; open it as a table.
- annotations.csvPositions and text for the figure annotations.
- before.pngThe figure before the change, for comparison.
- after.pngThe figure after applying the settings in this article.
- after.pdfThe result in PDF format, for viewing and page layout.
For general panel assembly, use the existing export guide. For resolution calculations, use the pixel calculator.
# Original simulated data, code and figures: CC0-1.0.
library(ggplot2)
d <- expand.grid(replicate = 1:6, time = c("Start", "End"), panel = c("A", "B"))
d$panel <- factor(d$panel, levels = c("A", "B"))
d$x <- factor(paste(d$time, d$panel, sep = "."),
levels = c("Start.A", "End.A", "Start.B", "End.B"))
d$y <- 3 + d$replicate * 0.22 + ifelse(d$time == "End", 1.1, 0) +
ifelse(d$panel == "B", 2, 0)
ann <- data.frame(panel = c("A", "B"), left = c("Start.A", "Start.B"),
right = c("End.A", "End.B"), y = c(6.5, 8.5),
label = c("Pair A", "Pair B"))
draw <- function(a) {
ggplot(d, aes(x, y)) + geom_point(size = 1.7, colour = "#17665c") +
facet_wrap(vars(panel), scales = "free_x", nrow = 1) +
geom_segment(data = a, aes(x = left, xend = right, y = y, yend = y),
inherit.aes = FALSE, linewidth = .45) +
geom_segment(data = a, aes(x = left, xend = left, y = y, yend = y - .2),
inherit.aes = FALSE, linewidth = .45) +
geom_segment(data = a, aes(x = right, xend = right, y = y, yend = y - .2),
inherit.aes = FALSE, linewidth = .45) +
geom_text(data = a, aes(x = left, y = y + .35, label = label),
inherit.aes = FALSE, hjust = 0, size = 3) +
scale_y_continuous(limits = c(2.5, 10), breaks = c(3, 5, 7, 9)) +
labs(x = "Time and panel", y = "Response (arbitrary units)",
caption = "Synthetic data; bracket labels identify the compared pairs") +
theme_classic(base_size = 10) +
theme(axis.text.x = element_text(angle = 30, hjust = 1),
panel.spacing = grid::unit(7, "mm"), plot.caption = element_text(size = 8),
plot.margin = margin(8, 10, 7, 7))
}
before <- draw(ann[c("left", "right", "y", "label")])
after <- draw(ann)
b <- ggplot_build(before)
a <- ggplot_build(after)
stopifnot(nrow(d) == 24L, nrow(b$data[[2]]) == 4L, nrow(a$data[[2]]) == 2L,
all(table(a$data[[2]]$PANEL) == 1L),
all(table(b$data[[2]]$PANEL) == 2L),
all(vapply(a$layout$panel_scales_x, function(s) length(s$get_limits()), integer(1)) == 2L),
all(vapply(b$layout$panel_scales_x, function(s) length(s$get_limits()), integer(1)) == 4L),
identical(b$data[[1]]$y, a$data[[1]]$y))
for(i in seq_len(nrow(ann))) {
valid <- as.character(d$x[d$panel == ann$panel[i]])
stopifnot(ann$left[i] %in% valid, ann$right[i] %in% valid)
}
ggsave("before.png", before, width = 1400, height = 900, units = "px", dpi = 300, bg = "white")
ggsave("after.png", after, width = 1400, height = 900, units = "px", dpi = 300, bg = "white")
ggsave("after.pdf", after, width = 1400/300, height = 3, units = "in", bg = "white")
write.csv(d, "synthetic.csv", row.names = FALSE)
write.csv(ann, "annotations.csv", row.names = FALSE)
capture.output(sessionInfo(), file = "session-info.txt")
cat("PASS: 24 simulated observations; before 2 brackets/4 categories per facet; after 1 bracket/2 categories per facet; observations unchanged; endpoints valid.\n")
Where did this example come from?
A Posit Community question posted 28 October 2026 prompted this example. It uses supplied descriptive labels. It demonstrates facet-specific annotation placement with ggplot2 only, with explicit labels and coordinates in the annotation table.
The original script, synthetic data and PNG/PDF figures are CC0-1.0, including commercial reuse. R retains GPL-2 or GPL-3 and ggplot2 MIT; install the required packages separately to run the code.
Learn R

