I can't seem to get the geom_segement to match up when add facet_grid
library(tidyverse)
library(plotly)
#create data frame in long format
df <- mtcars %>% rownames_to_column(var = "car") %>% 
  select(car, mpg, disp, cyl) %>% 
  mutate(car = as.factor(car)) %>% 
  pivot_longer(cols = c(mpg, disp)) %>% 
  rowwise() %>% 
  mutate(target = runif(1, value*.8, value*1.2))
#create ggplot 
   ggplot(df) +
    scale_x_discrete() +
     geom_col(aes(x = car, y = value)) +
     geom_segment(
       aes(
         x = as.numeric(car)-.25,
         xend = as.numeric(car)+.25,
         y = target,
         yend = target
       ),
       linetype = 'dotted',
       color = 'black'
     ) +
      facet_grid(
        rows = vars(cyl),
        cols = vars(name),
        scales = "free",
        space = "free_y"
      ) +
      coord_flip()
As you can see below the 'reference lines' I'm creating with geom_segement aren't correct, they should be over the geom_col()

