Shelley (1797-1851), the wife of the poet Percy Shelley, was actually inspired to write her story by a nightmare. In the summer of 1816, Shelley and her husband visited Switzerland. During their time in Switzerland, the Shelleys stayed at the Villa Diodati near Geneva. They regularly visited with their neighbors, the poet Lord Byron and his doctor. According to Diane Johnston in her introduction to the Bantam Classic edition of Frankenstein:
[The Shelleys and their neighbors] were compelled by the "wet, ungenial" weather to spend a great deal of time indoors, time which they spent reading ghost stories and discussing "various philosophical doctrines," among others "the nature of the principle of life, and whether there was ever any probability of its ever being discovered and communicated." The party, comprised after all of talented writers, agreed that each would write a ghost story of his own. For some days, Mary Shelley tried to think of hers, and each morning, upon being asked whether she had thought of one, was obliged to say no; but one night after the company had been discussing galvinism [electricity produced by chemical action] and the reanimation of corpses, her night was fitfully disturbed...(p. viii-ix).
Mary Shelley later described her experience that night:
When I placed my head on my pillow I did not sleep, nor could I be said to think. My imagination, unbidden, possessed and guided me, gifting the successive images that arose in my mind with a vividness far beyond the usual bounds of reverie. I saw--with shut eyes, but acute mental vision--I saw the pale student of unhallowed arts [Frankenstein] kneeling beside the thing he had put together. I saw the hideous phantasm of a man stretched out, and then, on the working of some powerful engine, show signs of life and stir with an uneasy, half-vital motion. Frightful must it be, for supremely frightful would be the effect of any human endeavour to mock the stupendous mechanism of the Creator of the world. His success would terrify the artist; he would rush away from his odious handiwork, horror-stricken...He sleeps; but he is awakened; he opens his eyes; behold, the horrid thing stands at his bedside, opening his [bed curtains] and looking on him with yellow, watery, but speculative eyes. (as quoted on pp. xxvi-xxvii in the Bantam Classic edition).
This story of the origin of Frankenstein is fairly familiar. What is less well-known is that one (indirect) inspiration for Shelley's novel was Darwin. The Darwin in question is not the author of the On the Origin of Species, however. Rather, it is Erasmus Darwin (1731-1802), a physician and scientist, who was also the grandfather of Charles Darwin. Among the topics being discussed that night on which Mary Shelley had her famous nightmare were certain experiments said to have been conducted by Erasmus Darwin, who had become famous for developing an early version of his grandson's theory of evolution. Specifically, according to Stephen Foster at victorianweb.org, Darwin had by 1769 come to the conclusion "that organisms have evolved through time; and his concurrent conjecture that all organisms share a common ancestor--what he termed a 'single filament'--formed in water by natural processes."
Given his view that life had originated through natural processes, rather than divine fiat, the notion that human beings could replicate those processes to create life would have been quite conceivable to Erasmus Darwin. At least that seems to be what Mary Shelley thought. As she wrote in her Preface to Frankenstein: "The event on which this fiction is founded has been supposed, by Dr. Darwin and some of the physiological writers of Germany, as not of impossible occurrence." However, she seemed skeptical for her part. As she further wrote in the preface: "I shall not be supposed as according the remotest degree of serious faith to such an imagination." Nevertheless, she apparently believed that by basing her story on a seemingly scientific premise, she had made it much more believable than a traditional tale of the supernatural. Or, as she put it: "The event on which the interest of the story depends is exempt from the disadvantages of a mere tale of spectres or enchantment."
In short, while Frankenstein was largely inspired by Mary Shelley's own imagination, some of its roots can be found in the philosophical and scientific speculations of her time. However, despite finding those speculations helpful for giving her work of fiction some degree of believability, she herself seemed rather skeptical of them.
Image of Richard Rothwell's portrait of Mary Shelley from Wikimedia Commons