Over the years, members of Congress who broke ranks with their party have tended to find more electoral success — in other words, it can pay to be a maverick. But in 2018, this wasn’t necessarily the case. Many Republicans who were less loyal to their party lost their re-election bids in this year’s midterms.

But a lot of Republicans lost this year — it was a Democratic wave year, after all. So to see how well party loyalty corresponded to electoral losses, we charted every member of the 115th Congress — Democrat and Republican, House and Senate — by their FiveThirtyEight party unity score, which measures how often a politician votes with the rest of their party, and then tracked whether they lost, left office on their own or hung on to join the 116th Congress when it’s sworn in early next year. On the chart below, Republicans who were voted out are marked with a big red X. Candidates who left office for another reason, such as retirement or resignation, are represented by the lighter pink diamonds, and the light pink circles reflect everyone who won re-election.

But breaking with the party didn’t always cost Republicans their seats. In fact, it may have helped Reps. Brian Fitzpatrick and John Katko, both of whom won re-election in districts carried by Hillary Clinton. However, Republicans with the lowest party unity scores also had the lowest average re-election rate.

If you look at the GOP chart, you will notice that there’s an uptick in the number of members who show up above the 65 percent mark, and then another uptick around the 70 percent mark. We can use those as dividing lines to split Republican House members into three groups. The group with the lowest party unity — below 65 percent — had a re-election rate of just 70 percent, well below the typical rate for House incumbents. But those members were also defending turf that was not as strongly Republican as some of their colleagues’: The average district in this group was 12 points more Republican-leaning than the country as a whole, and 23 of these districts had partisan leans of less than R+8.5. This is notable because Democrats currently lead the national House vote by about 8.5 points, which means that the pro-Democratic national environment essentially cancelled out the pro-Republican tilt of those districts, leaving Republican incumbents there vulnerable. That vulnerability likely contributed to the higher loss rate among this group.

Meanwhile, Republicans with a party unity score that fell in the 65 to 70 percent range held seats with an average partisan lean of R+23, and 84 percent of them won re-election. Those with an even higher party unity score (greater than 70 percent) had even more Republican-leaning seats (R+29 on average), and they won re-election at a 91 percent clip. Since so many Republicans with lower party unity scores are leaving Congress this year, and since this year’s electoral losses mean the GOP will have fewer battlegrounds to defend in the next election, House Republicans may be more unified than the Democrats in the next Congress, although we don’t yet know how the ideology of the new members joining their ranks will change things.

Republicans did have a lower average unity score than Democrats (68 percent compared to 80 percent), which suggests that the average Republican was more likely to vote against the party line than the average Democrat was. Some of that can be explained by the partisan lean of districts. For all members, the correlation between the partisan lean of a district and party unity score was 85 percent, which suggests that members in more competitive seats tended to be less faithful to their parties. With the GOP holding most battleground districts in the 2018 midterms, it makes sense that the party had more members trying to show an independent streak so that when they came home to campaign they could argue they put their constituents’ needs above party loyalty. The GOP’s healthy majority — 241 seats at its peak — allowed some members to break with the party to cast politically advantageous votes without actually endangering the passage of a bill; for example, a dozen Republicans, almost all of them from California and the Northeast, voted against the GOP tax bill because of its effect on state and local taxes.

On the other hand, House Democrats suffered only two election defeats — and both were primary losses: Reps. Michael Capuano of Massachusetts and Joe Crowley of New York. Both were among the 35 most loyal Democratic members, suggesting their losses had less to do with being good Democrats and more to do with other factors, such as being white men in districts with diverse Democratic electorates looking for new faces.

Speaking of new faces, there will be many on the Democratic side of the House next year, which makes it a little hard to know at this stage what the party’s ideology might look like in 2019 and beyond. With Democrats now in the majority and holding many battleground districts they won in 2018, they may emerge as the party with a lower average unity score — many new members will be part of more moderate Democratic caucuses, such as the Blue Dogs and the New Democrats. On the flip side, progressives are set to yield more power than ever within the party, which will further complicate the Democratic leadership’s efforts to maintain party unity.

Turning to the Senate, we immediately see that moderate Democrats took a hit in 2018. Democrats had to defend 10 seats in states carried by President Trump — and they lost four of them.

Among the Democratic losers were three of the least-faithful to their party: Sens. Joe Donnelly of Indiana, Claire McCaskill of Missouri and Heidi Heitkamp of North Dakota. Sen. Bill Nelson of Florida also lost, though he had a higher loyalty rate; still, he was on the lower end among Democrats as a whole. That said, West Virginia Democrat Joe Manchin won — by 3 points — probably in part because of his low party unity score in his deep-red state. For example, it may have helped that he was the only Democrat to vote to confirm Brett Kavanaugh to the Supreme Court.

As for Republicans, the more moderate Dean Heller of Nevada was a casualty in this year’s general election. The GOP also got an early surprise, however, when Sen. Luther Strange lost the primary runoff in Alabama’s 2017 special election. Strange had the highest party unity score in the GOP during his one-year tenure in the Senate, but it wasn’t enough when he was up against the anti-establishment Roy Moore, who was later brought down by scandal. Democrat Doug Jones ultimately won that Senate seat, but he will face a tough re-election bid in 2020. That said, he currently stands out as the member with the lowest party unity score in the entire Senate, and he will certainly hope to have a trajectory more like Manchin than like Heitkamp and other red-state Democrats who lost in 2018.

Susan Collins of Maine had the lowest party unity score among Republicans, and she too faces re-election in 2020. Given the loss of both parties’ more moderate members here in 2018, if both Jones and Collins were to lose in 2020, we could be headed for a Senate that has fewer middle-of-the-road members and higher levels of party unity on both sides — or, to put it another way, a more partisan Senate.