Hello all,
I'm working with monthly rainfall data over a 40 year period and the goal is to see if the month that has the mean/median rainfall has been shifting over time (for example in April in 1988 to June in 2018), test whether this shift is significant and graphically present the shift. I'm attaching a dummy of the data structure below (with the median as an example).

Rain: shows rainfall in mm
med: show median rainfall for the year
med_rain: shows cumulative rainfall over months in each year

I want to generate the variable "marker" that automatically replaces the value of the var with 1 to the closest match between med/mean and med_year.

On my second problem: what is the best way to structure the data to generate a graph that has the years on the x-axis, months on the y-axis and has dots showing the month with the mean/median.

Many thanks in advance for your time and help!
Best, Wameq

year month rainfall med med_rain
1988 1 42 127 127
1988 2 65 127 107
.
2017 1 65 232 65
2017 2 75 232 140