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 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.
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:
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.
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.