I want to highlight add y-value text to a plot, but only for those points where I set up x-axis breaks. In my original data, x values are discreate, but to keep things simple lets use a sequence from 0 to 125 as an example and I hope i can transfer the solution for my data on my own. If I simply put
... + geom_text(aes(label=y),size=3) + ...
it'll result in a mess that can't be read. E.g.
This is what my code for the plot and for my example data looks like.
data %>%
group_by(x) %>%
summarise(y= sum(y,na.rm = TRUE)) %>%
ggplot( aes(x=x,y=y,group=1)) +
scale_x_continuous(breaks = c(1,50,75,100,125))+
geom_text(aes(label = y), size = 3)+
geom_line()
# while the data after summarised looks somethat like this
x <- seq(1,125,1)
y <- x^2
data <- data.frame(cbind(x,y))
Thank you very much for all responses. Kind regards
EDIT: In my comments I referred to "strange behavior" and I just wanted to show you what happens on my real data.
This does not happen when using the marked answer.



