How did Isaac newton invent gravity?

Newton didn't invent gravity. He was simply the first one to clearly recognize it

for what it is, and to describe it mathematically.