I worked for a pharmaceutical company at one time, a small one, and I can assure you that the R&D costs are astronomical! Even minor medicines went through many months, if not years, of development and testing, and not all of them were successful. So when you are paying those high prices for the drugs that let you lead a comfortable life, you are also having to pay for the research for other drugs which never made it to market.
Add to that the high cost of manufacture for those drugs, too. From the top of my head, every raw material which was purchased for production had to be rigorously tested to meet FDA standards. Every step in the production process had to be tested, repeatedly. Repeated sterilizing of equipment, relatively high cost of training production personel, as compared to average factory workers, added to the cost. Testing continued through the packaging process and even sampling from the warehouse.
That's not to say that the drug companies don't pad their prices, but after seeing the process in action, I can't fault them too much.