One theme of the 2018 election was that Democratic senators from rural, red states became an endangered breed. Three Democratic senators on deep-red turf — Joe Donnelly of Indiana, Claire McCaskill of Missouri and Heidi Heitkamp of North Dakota — lost their seats. Two others managed to squeak out wins — Jon Tester of Montana and Joe Manchin of West Virginia — but they saw their support shrivel up in many parts of their states.

In the six years since these senators last appeared on the ballot (in 2012), Democratic support has become increasingly confined to America’s metro areas. In their states, which are heavily rural, it’s tough for candidates to win with cities alone — they must appeal to rural voters. These five Democratic incumbents didn’t all manage that; as it has for Democrats nationally, their support deteriorated significantly relative to 2012 in areas outside of cities and suburbs, according to a county-by-county analysis of U.S. Senate results.

Let’s start in Indiana. After winning by 6 percentage points in 2012, Donnelly lost by 6 points in 2018. Donnelly improved upon his 2012 performance in only three counties — Boone, Hamilton (these two are in the Indianapolis suburbs) and Monroe (home of Bloomington, where the Indiana University flagship campus is located) — and even there, just barely. As you can see in the map below, the size of the circle — which represents the margin of Donnelly’s or his Republican opponent’s win — stays about the same in these counties. In contrast, the red circles in most of Indiana’s rural counties swell in size, representing how most other counties — especially lower-population ones — swung far out of Donnelly’s reach. Donnelly’s loss of rural support, coupled with his inability to make up for those losses with more votes in urban areas, sealed his fate.

In Missouri, McCaskill lost by 6 points six years after winning her previous race by 16 — a really robust margin for a Democrat in a state that Mitt Romney simultaneously won by 9 points. But her overperformance in 2012 was thanks, in part, to her opponent, Rep. Todd Akin, who was abandoned by the Republican Party after his “legitimate rape” comments. In 2018, her Republican opponent Josh Hawley was a better candidate than Akin, and McCaskill didn’t outperform her previous vote margin in a single county. She lost the least amount of support in Missouri’s urban areas, particularly St. Louis, Kansas City and Columbia (home of the University of Missouri’s main campus). But her margin dropped by huge amounts in less populated counties. In the most severe example, she lost Clark County (population 6,807), in the northeast corner of the state, by 45 points. She won it in 2012 by 16 points — a 61-point swing! McCaskill proved unable to avoid this urban-rural difference despite a concerted effort to appeal to rural voters.

North Dakota’s U.S. Senate margin shifted to Republicans by 12 points — from a 1-point Heitkamp win in 2012 to an 11-point Heitkamp loss in 2018. Re-election was always going to be difficult for Heitkamp in such a red, rural state, but she did worse in 2018 in every single county except three. The one county where she improved the most was Cass County (Fargo), which is by far the most populous county in the state. The other two counties where Heitkamp did better are actually quite low in population: Rolette County and Sioux County. But they are both around 80 percent Native American, a heavily Democratic demographic that may have been especially energized to go to the polls this year because of North Dakota’s new voter-ID law, which made it harder for many people who live on reservations to vote.

Tester’s performance in Montana, however, defies clean categorization. The rural-urban sorting is still there to some degree: Tester improved upon his 2012 performance in 10 counties (including four of the six with populations greater than 50,000 — those containing Bozeman, Butte, Helena and Missoula) and did worse in 46 mostly smaller ones.

But there are exceptions: Tester lost Yellowstone County (Billings), the state’s largest county, by 4 points after winning it by 1 point in 2012. And Tester improved his margin by 8 points in Beaverhead County and 5 points in Madison County, both of which have populations under 10,000.

What probably saved Tester is that he didn’t drop off by as much in sparsely populated counties as other Democratic senators did. In counties with fewer than 20,000 residents, Tester’s average dropoff was 8 percentage points. Donnelly’s was 27 percentage points, Heitkamp’s was 21 points and McCaskill’s was 43 points. As a result, Tester won the state overall by 3.6 points — just a shade worse than his 2012 margin of 3.7 points.

A big part of why Tester triumphed while the other three didn’t is that he appears to have been the only one who maintained his appeal among rural voters. That might be because voters in Montana are significantly more elastic — that is, persuadable — than those in Indiana, Missouri or North Dakota.

Democrats were probably lucky to hold onto the final red state we looked at: West Virginia. Manchin’s 24-point win in 2012 all but vanished in 2018; he won by 3 points. Manchin improved upon his 2012 margin in just one county, Monongalia (Morgantown). He more or less held steady in West Virginia’s largest county, Kanawha (Charleston), faring just 3 points worse. Manchin consistently lost ground in the remainder of the state’s mostly sparsely populated counties, including Mingo County, the heart of West Virginia coal county. Once reliably blue, Mingo County leaned 16 points more Republican than West Virginia as a whole in the 2018 Senate election.

Overall, in all five states, there is a clear relationship between the size of a county and how its political preferences changed from 2012 to 2018.

Democrats lost more ground in lower-population counties The average margin shift from 2012 to 2018 in U.S. Senate races in Indiana, Missouri, Montana, North Dakota and West Virginia, by county population Average margin shift Counties by population Indiana Missouri N.D. Montana W. Va. 0-10k people R+25 R+47 R+22 R+9 R+29 10-50k R+25 R+39 R+15 R+5 R+30 50-100k R+13 R+28 R+12 D+1 R+20 100-500k R+9 R+18 D+3 D+5 R+2 500k+ R+2 R+9 N/A N/A N/A North Dakota, Montana and West Virginia have no counties with more than 500,000 residents. Sources: U.S. Census Bureau, ABC News, secretaries of state

As you can see, the smallest counties overwhelmingly lurched toward the Republican. Higher-population counties shifted less dramatically to the right — and even moved toward the Democratic incumbent in some states. Since most people in Indiana, Missouri, North Dakota, Montana and West Virginia live in lower-density areas, that was a recipe for Republican success. (Montana and West Virginia are exceptions, of course, although Manchin’s support did erode; it’s just that he had such a large cushion from 2012 that he could withstand the sharp dropoff. Tester is the only one who was able to keep rural losses to a minimum, and even then, Montana’s urban and rural areas still diverged to a small degree.) While the combination of lower Democratic support in rural areas and higher Democratic support around cities may help the party in more urbanized states like Texas, it’s a bad trade for them in states like these and may make winning a majority in the Senate, with its small-state bias, more difficult.