|MadSci Network: Astronomy|
The spectral classes were actually assigned several decades before the Hertzsprung-Russell diagram was developed. Angelo Secchi, back in the 1860s, attached a spectroscope to a telescope. On observing various stars he found that there were various "lines" of spectra missing. Using his observations he decided there might be four different kinds or classes of stars.
Robert Bunsen, of bunsen burner fame, and Gustav Kirchhoff were doing research in the spectra of burning different chemicals around this time. As astronomers made further observations and a better understanding of what the spectra might represent progressed, a classification system developed using certain absorption lines of hydrogen. They assigned stars into classes with letters from A to P.
At the turn of the century a group of astronomers at the Harvard College Observatory, lead by Edward Pickering examined the spectra extensively. They ended up dropping many of the old classes and organized the stars into seven groups, OBAFGKM. The order of the groups comes from the decreasing temperature of each class as seen on the H-R diagram. If you want to remember the order just learn this phrase: "Oh, be a fine girl, kiss me!"
Try the links in the MadSci Library for more information on Astronomy.