Merriam-Webster defines heir as "one who inherits or is entitled to inherit property" and legatee as "someone who receives money or property from a person who has died."
Is there any difference between these words in meaning or usage?
An Ngram shows that heir has always been much more common than legatee, so I wonder if the latter has a narrower meaning. Then again, it seems to me that heir is almost always used to refer to the child, niece, or nephew of the person whom the heir inherits from, so perhaps heir is used for blood relatives (after all, it's also used in the sense of "heir to the throne," which is determined by blood relation) and legatee is a broader term for anyone who inherits, such as a friend or neighbor. However, neither definition actually specifies anything about who's doing the inheriting.
Are these words meant to be used in different contexts or are they completely interchangeable?