Mary Shelley references how Frankenstein came to be in the introductions to her novel. One of the most poignant introductions is included in the 1831 publication of Frankenstein.
The historical tale of how the novel came to be is renowned. Mary Shelley, accompanied by her husband (Percy Bysshe Shelley), were vacationing with Lord Byron and John Polodori. Lord Byron decided to pose a challenge to create a ghost story. The four agreed that it sounded like a good idea, given they were confined to the house due to rain.
After a few days, Mary Shelley had a dream, or more of a nightmare. She dreamed about a "student of unhallowed arts" bent over his "hideous phantasm of a man." The student, exhausted by his labors, awakens to find his "hideous corpse" staring at him with yellow eyes.
Upon awakening, Mary Shelley realized that she had her ghost story. The image of the creature frightened her so much that she realized it would frighten others as well. The story was completed upon her husband's urging.