In a simple scenario, when the panels have common axes, and the lines extend over the entire y range, you can draw lines along all gtable elements, finding the correct coordinate transformation npc (cf previous post, updated as ggplot2 continues to change)
library(ggplot2) library(gtable) library(grid) dat <- data.frame(x=rep(1:10,2),y=1:20+rnorm(20),z=c(rep("A",10),rep("B",10))) p <- ggplot(dat,aes(x,y)) + geom_point() + facet_grid(z~.) + xlim(0,10) pb <- ggplot_build(p) pg <- ggplot_gtable(pb) data2npc <- function(x, panel = 1L, axis = "x") { range <- pb$layout$panel_ranges[[panel]][[paste0(axis,".range")]] scales::rescale(c(range, x), c(0,1))[-c(1,2)] } start <- sapply(c(4,8), data2npc, panel=1, axis="x") pg <- gtable_add_grob(pg, segmentsGrob(x0=start, x1=start, y0=0, y1=1, gp=gpar(lty=2)), t=8, b=6, l=4) grid.newpage() grid.draw(pg)

source share