Roland Muser wrote a book, Long-Distance Hiking: Lessons from the Appalachian Trail, based on surveys of 136 long-distance hikers, each of whom spent 3-6 months on the trail. Some relevant quotes (p. 133):
Two or three hikers had run-ins with local inhabitants, and some reported uncomfortable hitch-hiking incidents. More seriously, two hikers were threatened with guns, and there was one (not officially reported) attempted rape. [...] When one considers that we are dealing with the experiences of 136 people over three to six months, the unpleasant occurrences were relatively few. [...] When asked what they considered the major hazards on the trail about which they might wish to warn new hikers, responses boiled down to three categories [...]
In these responses, 23 people reported trouble due to other people (thefts, encounters with drunks, ...), 19 cited "trail/environmental hazards," and 14 issues to animals. The most common advice from ATers in terms of avoiding crime (such as getting your pack stolen) was not to camp at public car-camping campgrounds.