Extension of my comment:
ggplot(X, aes(x = x, y = y, color = grp)) +
geom_point(shape = 19) +
stat_smooth(method="lm", formula=y~1, se=FALSE)+
theme_bw()

Thus, a linear model with a constant term that returns the average value is applied. Sign this answer for the main idea.
Edit: response to a very clever OP proposal.
It looks like you can use quantile regression to create medians!
library(quantreg)
ggplot(X, aes(x = x, y = y, color = grp)) +
geom_point(shape = 19) +
stat_smooth(method="rq", formula=y~1, se=FALSE)+
theme_bw()

stat_smooth(method=..., ...) , , predict(...). , rq(...) rq predict.rq(...). se=TRUE, .