Search code examples
rtime-series

How to write the abscissa of the maximum under x'x


I'm plotting a time series data, say 'data1', I use plot.ts(data1) then I use abline(which.max(data1))

Now I want to add the abscissa of the maximum point, say x-abscissa=19, but sometimes it appears confounded to the number that already exist in x-axis, My question: how can I write the abscissa of the maximum below the number that already exist on x'x.

s=c(1,1.5,2,4,1,1,5,3,5,2,3,5,2,5,2,2,4,2,7,5,2,3,5,2,3,5,2,3,5,2,3,5) 
plot.ts(s)
abline(v=which.max(s), col= "red", lty=2, lwd=1)
axis(1,which.max(s))

Solution

  • Does this work for you Salman?

    # axis(1,which.max(s))
    library(glue)
    label <- glue("Max is {max(s)}")
    text(which.max(s), 0.2*max(s), label)