I have some code like this:
seq(0, 2*pi, length.out = 100) %>%
cbind.data.frame(t = ., Y = sin(.)) %>%
qplot(t, Y, data = ., geom = "line")+
geom_segment(aes(y = mean(Y), yend = max(Y), x = , xend = ))
I want to create a geom_segment
where the arguments x
and xend
take on the value of t
for which Y
is highest. I found the question that describes how to find the value of one variable based on the maximum value of the other variable, however, I don't know how to apply that solution so that it can be used within a ggplot
call, without saving the object to the environemnt. Any help would be appreciated, thanks.