It may work for you?
library(dplyr)
df2 <- df |> group_by(x) |>
summarise(y = max(y))
ggplot(df,aes(x,y), col = x) +
geom_point() +
geom_point(data = df2,
pch = 21, fill = "red", color = "black") +
geom_line(data = specials, aes(x = positions, y = maxes))