Beyond the captive market, there is the world wide cost shifting. Countries with socialized health care systems “negotiate” the prices they are willing to pay for medications. They are effectively offering a token amount as an alternative to otherwise violating manufacturer patents and making a generic version themselves. In effect, American prescription users are financing all the research and testing for the entire world. If the costs of research and failed drugs were dispersed among several billion folks instead of a hundred million, our prices would be lower.
You are correct, we are subsidizing most of the R&D, but that isn't the whole reason for the price.
The other side is a wide gap between actual price, and perceived price. I had to take some acid controls for a stomach condition. I payed $3, my insurance paid $80.
The SAME drug is in Prilosac OTC, and costs $30 for the same dosage.
That is a $50 mark up in actual price, but I only perceive the $3 cost.