Many a time I've asked what the difference is between an analogy and a metaphor. I've asked it to my teacher, on internet sites, to my parents, so on and so forth. I got a different answer every time, and I never fully grasped what the difference is, so what is the difference?
Briefly, analogy is a perceived likeness between two entities; metaphor is one “figure of speech” which you might use to communicate that likeness.
For example: you may recognize that many Greek and Shakespearean tragedies have a similar structure: a phase of increasing conflict between opposed sides or characters, a major confrontation between the opposed characters, and a phase in which the opposition is worked out and resolved in one character's victory and the other's defeat.
It may then occur to you that this structure is very like the shape of a pyramid isosceles triangle, which rises from a baseline to a central point and then falls back to its baseline. You have then perceived an analogy betweeen a temporal phenomenon and a spatial one.
To communicate this analogy, you may employ metaphors. You name the central confrontation the “climax” —this is the classical name for a figure of speech, which is itself a metaphor: the word means “ladder”. You then name the first phase the “rising action” and the fourth stage the “falling action”.
Subsequently you perceive that the rising action has its own inceptive phase, when the characters and conflicts are introduced. These don’t fit so well into the triangular analogy, so you cast about for another analogy. One that occurs to you that of a public display of new works—so you employ the metaphor “exposition”. And for the final phase, when everything has “fallen” all the way back to the “baseline” you adopt the Greek word “catastrophe”, meaning “turn or fall down” or, metaphorically, “come to an end”.
And then you publish this elegant treatment of dramatic structure to universal applause, and the critical world pays you the ultimate honor of putting your own name on the basic metaphor: it becomes known to all succeeding generations as “Freytag’s pyramid”.
Most of those succeeding generations, however, find singular deficiencies in the model. They point out, for instance, that “exposition” of new facts occurs continuously throughout a play, and that many different actions occur alongside each other. They perceive a different analogy, that between dramatic structure and a tangle of threads; and to express this analogy they employ the metaphors complication (literally, a “folding together”) for the developing action and dénouement, a French word meaning “untying”, for the conclusion.
The analogy is what is expressed; the metaphor is how it is expressed.
Note, however, that metaphor is not the only way to express analogy. You may also employ simile: instead of talking about the analogous entity instead of the primary entity you may say that your primary entity is like the analogous entity. Or you can avoid language altogether and express the analogy in graphic form, using a labeled picture.
A metaphor is an implicit simile, while analogy is an explicit one. Put differently, a metaphor is literally false, while an analogy is literally true. Metaphors need a bit more imagination to interpret, while analogies are readily apparent.
"My cat is affectionate" is an analogy. You can literally see the cat shows behavior deemed affectionate. The comparison is straightforward, 1:1, between the cat's behavior and our idea of what "affectionate" looks like.
"My cat is a rock" is a metaphor. You can see literally the cat isn't a rock. The comparison isn't straight forward and asks us to imagine more so what it means to for the cat to be a "rock".
"My cat is an affectionate rock" is both, an analogy and a metaphor. "Affectionate" is apparent, while "rock" isn't.
An analogy is specifically a discursive or argumentative technique; a metaphor is strictly a literary one.
When you make an analogy you do it specifically to illustrate a point. A heart is like a two bicycle pumps. See? here are the valves, here is are the pistons. It's part of a discussion between you and the reader about items at hand.
A metaphor is emotional, allusive, discursive. His heart is like the sea. I cannot explain any sea-like parts of the heart and I'm not trying to prove anything about it. I just you to feel that his heart -- not the cardiac organ, of course, but his love for the heroine -- has the power and the restlessness of the sea.
"Metaphor is a term used in literature for a special type of comparison. Analogous or analogy is a generell term in a lot of scientific branches and describes a special kind of similarity.
Here is a definition of analogous organs in biology: https://www.biology-online.org/dictionary/Analogous
Stylistics or rhetoric is a very old discipline elaborated by the Greeks and adopted by the Romans and the terms were adopted in the Latin/Greek form in modern languages. Metaphor and analogy have something in common, but metaphor means transfer from one area to another. As other disciplines of science which use the term analogy or analogous don't see a transfer they did not use metaphor. Biology speaks of analogous organs which have something in common, but there is no transfer.
Added: I now realize that "analogy" is used as a literary term as well. The problem which these terms for literary devices is that comparison, analogy, simile and metaphor are overlapping terms and that precise definitions are lacking. Comparison is a general term, simile and analogy mean the same, but simile is more a literary term and analogy is in my view only a variant for simile. The clearest term is metaphor, a comparison without like/as/as if. But there are cases where it is difficult to decide whether something is a metaphor or not. Generally one may say terms of rhetoric have their difficulty, precise definitions are lacking, there are large overlapping areas and often views of different authors diverge as to what is what.
By the way, the best book I know about this topic is by Heinrich Lausberg (In German). Link here
An analogy is logically consistent whereas a metaphor is emotionally consistent (being consistent in one respect, however, doesn't exclude the other.) Both are used to present similarities between the objects compared.
For example, the term "snake oil" is a metaphor for an ineffective and fraudulent product, even if it contains neither a snake nor its oil. A "snake oil salesman" is an analogy for someone who doesn't scruple to sell such products.
I remember this confusing even my high school English teachers.
The short answer is that a metaphor is one kind of analogy.
Broadly speaking, analogies are a problem-solving tool -- you use them on a daily basis to make sense of your world. For example, maybe you read in passing that Switzerland is divided into cantons. If you live in the United States and you've never heard of a canton before, a helpful analogy might go like this: "Oh, cantons in Switzerland are like states in the USA -- a way of dividing a territory." In this sense, cantons are analogous to states, and the comparison can help you understand an unfamiliar term.
Metaphors are also comparisons. While they can shed light on an unfamiliar concept, they are most often used to connect drastically unrelated concepts in order to make a point, provide humor, or because the writer is trying really hard to be deep.
For example, in the Qur'an:
The metaphor of those who take protectors besides Allah is that of a spider that builds itself a house; but no house is flimsier than a spider's house, if they only knew. (Surat al-Ankabut, 41)
Obviously the unfaithful are not actually spiders -- nor are they in any way similar to spiders. The text is making the point that, since only Allah can offer protection, the infidels are so vulnerable, they might as well be spiders.