What happens after death is a thing of faith as there is no clear answer. The following is based on the belief of life after death.
For most people, when you die, you may spend a brief time, say 3 days, on earth simply to watch over your loved ones, or your spirit is in denial. If you have no regrets and your family does not need you to watch over them, then you ascend to heaven, or are reincarnated or whatever it is you believe.
Regarding "ghosts" this happens when someone died suddenly, a horrific way, denies actually being dead, refuses to let go of their previous life, or feels they need to watch over a loved one for whatever reason. There is the other rare one where a spirit does not wish to be reborn, so they choose to wander the earth.
Granted this is all speculation and theories, not proven fact. Read some articles on the subject and choose for yourself.