This can be considered a follow-up to this question. The answer to the question uses this code:
ggplot(mtcars, aes(x = wt, y = qsec)) +
geom_point() +
ggh4x::facet_grid2(gear ~ vs, scales = "free", axes = "x", independent = "all") +
geom_vline(aes(xintercept = mean(wt)))
To produce this plot:
However, I noticed that the displayed xintercept is the same in all facets, around 3.25. I suspect that the function is calculating the overall mean of wt and then plotting it, instead of plotting the mean of wt for all different levels of faceting variables. How can I achieve this?
Calculating an intermediate summary dataframe which is then passed as data to geom_vline is not an acceptable answer because I am trying to learn how to invoke the data which was passed to ggplot from within geom_line. If that is completely impossible to do without the intermediate dataframe, then your answer should be just "that is completely impossible to do without the intermediate dataframe". Thanks.


