Debt and Credit Ratings

Charles Franklin has a very useful chart (click the link for a bigger view) highlighting the murky relationship between how much debt a country has outstanding and its credit rating:

Do sound budget practices lead to high ratings, or do high ratings lead countries to borrow a lot of money? After all, if global investors are going to grant you cheap money on grounds of low risk, then why not take advantage of the opportunity?