This is only partly a myth; there are contemporary accounts from Newton's acquaintances noting how he described being inspired by observing the fall of an apple from a tree. It was the fact that an apple falls from a tree specifically in the direction of the Earth's centre that was said to have piqued his curiosity.
The apple falling on his head seems to have been a later embellishment.