What is the difference between a metaphor and an analogy?

An analogy shows similarity between things that might seem different like an extended metaphor or simile. It can be a logical argument: if two things are alike in some ways, they are alike in some other ways as well. Analogy is often used to help provide insight by comparing an unknown subject to one that is more familiar. It can also show a relationship between pairs of things. For example, an analogy of an ecosystem would be a class consisting of many students of different races.

A metaphor is a figure of speech that uses one thing to mean another and makes a comparison between the two. For example, my brother is a pig. (It means the brother eats a lot)