The title is a question that came from one of my students today. I am not an expert of the history of science. However, I love to answer this question since Newton is my idol:)
As far as I know, “Newton discovered Gravity when he saw a falling apple” is a legendary story:) He might be stimulated by the observation of the falling of objects from rest. More importantly, he made an “Inductive Reasoning” (a term from Newton means “deriving from empirical observations”) that the moon would fly away from the Earth if there was no force/constraint between them. Newton called this force “gravity” and assumed the gravitational force exists between any two objects with masses.
Later, he used his theory of gravity to prove successfully some important/famous astronomical observations, especially, Kepler’s second law: “A line joining a planet and the Sun sweeps out equal areas during equal intervals of time”.
Most of Newton’s theories of physics are covered in his work of three books “Mathematical Principles of Natural Philosophy”. Interestingly, Robert Hooke, whom Hooke’s Law was named after, claimed Newton copied the inverse square equation for gravity from him.
References:
https://en.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation
https://en.wikipedia.org/wiki/Kepler%27s_laws_of_planetary_motion
https://en.wikipedia.org/wiki/Philosophi%C3%A6_Naturalis_Principia_Mathematica