Allegory is a very formal and controlled kind of comparison. It tends to be applied only to literary works of full length - and their derivatives. It is a figure where one story is told in terms of a different world - where a coherent construction of symbols is used to represent a coherent view of the 'real' world. For example, in the thirteenth century, the French writer Guillaume de Lorris wrote a poem called le Roman de la Rose. It was later continued by Jean de Meung and translated into English by the great poet Geoffrey Chaucer (?1340-1400) as The Romaunt of the Rose. In this, the world is seen as a flower garden, and people as flowers. (The loveliest, of course - representing the ideal woman - is the rose.) The English poem lasts some 7,700 lines, so it is a well worked out scheme, not just a casual imaginative comparison.
Some 400 years later, Jonathan Swift wrote about the politics of his own time in the disguise, or allegory, of travels into marvellous countries, in Gulliver's Travels (1726). Nowadays, many people think of this purely as a children's story (though the name "Lilliputian" which was invented for the book has become a metaphor (rather a Dead metaphor) for anything very small, and much less important than it is said to be); but it was originally a satire on contemporary politics, at a date at which satirists could be harshly punished by law.
Another well-known allegory, and one from nearer our own times, is George Orwell's Animal Farm (1945 - a cartoon film was released in 1954). This is also a satire, where the world of twentieth century human politics is imagined as a farmyard in which totalitarian politicians are seen as pigs, and the hard-working proletariat as carthorses - and humans are the terrible enemy.