As a general rule, we use "in" for months, years, centuries and long periods, and "on" for days and dates. However, there are exceptions.
It all depends on how specific you want to be. Obviously, years comprise of days; days comprise of hours and minutes etc. For example, you might be talking about something that could occur on any day within a month, so you would use "in":
I went swimming 10 times in a month.
However, if 'months' were the ultimate unit (ie there is no need to be specific about any smaller unit of time), you might use "on":
I visit my parents on alternate months.
Your example is about past data, and seemingly about something which occurs only once per year (if at all). Arguably, you could use either, because you are talking about something that occured within certain years, but on the other hand you are comparing years as whole units of time.
Alternatively, you could use neither:
Some years, the swallows returned; other years, they did not.