Apologies for the déjà vu, but I made a big enough error in a previous post that I think it merits a second try. The following graphic, created by Steve Haroz, shows relative spending on scientific research and the military during 2011, and also shows total NASA spending -- corrected for inflation -- over its entire existence from 1958 through 2011. (I had previously, and mistakenly, guessed that the NASA total was in unadjusted nominal dollars.) This of course makes the comparison all the more striking.
The Department of Energy has responsibilities related to nuclear weapons, and the chart accounts for those as part of the military budget rather than civilian research.
It should be noted that some of the military budget does go to fund scientific research in everything from oceanography to meteorology to medical research even in areas you might not expect, such as breast cancer. While not trivial in dollars terms, it's a small fraction of the total military budget and hence doesn't affect the point of this graph.
You can find more details on Steve Haroz's blog and this interactive graphic. (Point at the parts of the bar for the raw numbers.) I'm grateful to him for correcting my misapprehension that the NASA total was in nominal dollars, and of course for having done the research and created the graph.
Incidentally, one might object that expenditures on veterans' benefits aren't a military expense as such, but it seems to me quite reasonable to include them. It would also make sense to add the cost of servicing the debt on recent wars (pretty much entirely financed with borrowed money), which would make the comparison even more stark.by