It seems like the Harry Potter author had the deaths of a lot of characters in mind, not just Ron Weasley. If not for an image that she'd carried in her head for the entire seven-book series, a certain towering guardian might not have survived.
On the Blu-ray edition of Harry Potter and the Deathly Hallows, Part 2, Rowling and Daniel Radcliffe sit down for a little chat in which Rowling reveals much about the genesis and ongoing development of the novels. And, after revealing that she thought about killing poor Ron—because it was a reflection of the fact that she herself "was not in a very happy place"—she talks about the image that kept loyal Hagrid alive and well.
She reveals that, from the very beginning of Potter, she knew that the ending of the story would feature [spoiler!] Hagrid carrying Harry's lifeless body out of the Forbidden Forest, and that they'd pass Harry's dead family and live loved ones along the way:
"That image kept him safe."It would also provide a perfect bookend for the series, given that Harry's story began with Hagrid carrying an infant Harry Potter and dropping him on the Dursleys' doorstep.