On Thursday, many Americans woke up to a possible diplomatic rift with Australia, after the news that President Trump and the Australian prime minister, Malcolm Turnbull, exchanged harsh words over a refugee agreement. It was all the more remarkable because a new survey — taken in the days before their conversation was revealed — shows that Australia is the nation that Republicans say is America’s strongest ally.

Rated as... An ally Not sure An enemy Places Americans say are allies Among... Democrats Republicans Independents Places Americans say are enemies Among... Democrats Republicans Independents Rated as... An ally Not sure An enemy

The episode was not the first international clash of Mr. Trump’s presidency. He belittled Mexico throughout his campaign and has annoyed many Mexicans with his aggressive talk on trade and immigration, insisting that they will pay for a border wall. He has also angered several European nations, including Germany, Britain and Italy, over his administration’s executive order restricting refugees and citizens of seven Muslim-majority countries from entering the United States.

What Australia, Germany, Britain and Italy have in common: Americans of both parties rank them near the top of their list of allies. The survey, conducted from January 28 to February 1, asked respondents to rate whether a country was an ally or enemy of the United States on a five-point scale: ally, friendly, not sure, unfriendly or enemy. The differences at the top of the list — between Australia, Canada and Britain — were small.

Mexico landed further down the list, but was still viewed relatively favorably, especially by Democrats. It ranked 42nd of the 144 places respondents were asked to rate, similar to the Philippines, Romania and Madagascar. The predominantly Muslim countries whose citizens were recently denied entry are near the bottom of the list. (A full list of the average results for all the places respondents were asked can be found at the bottom of this article.)

Of course, Americans are not monolithic in their beliefs. For some countries, respondents’ opinions varied greatly depending on their political party.

Rated as... An ally Not sure An enemy Places Democrats viewed much more favorably Among... Democrats Republicans Independents Places Republicans viewed much more favorably Among... Democrats Republicans Independents Rated as... An ally Not sure An enemy

Russia is one notable example. Democrats emphatically identified Russia as an enemy; only North Korea ranked lower. Republicans still had negative views about Russia, but not as negative. Elsewhere, Democrats had relatively more favorable views of Cuba, Iran and Syria; Republicans had more favorable views of Israel.

One reason for some differences, particularly with regard to countries in Africa and Latin America, may be the different racial compositions of the parties (Democrats are significantly more diverse).

Doug Rivers, the chief scientist at YouGov, said: “Americans tend to think that countries populated by people of their own race are allies of the United States. For example, African-Americans rate Ethiopia, Nigeria, Ivory Coast and Sierra Leone as allies, while white Americans consider these countries to be somewhat unfriendly. Similarly, Latinos, but not whites, considered El Salvador to be an ally. European countries are rated more friendly by whites than by either African-Americans or Latinos.”

Comparing the new survey with a nearly identical YouGov survey conducted about three years ago, the scatterplot below shows the shifting in Democratic and Republican views. In the previous survey, for example, Democratic and Republican views on Russia were roughly the same.

Republicans are more likely to see countries as enemies than Democrats. On average, a Republican’s rating of the bottom 10 countries was about a quarter-point lower on the five-point scale than an average Democrat’s, Mr. Rivers said.

As the animation shows, there has been some movement in Americans’ attitudes toward other countries over the past three years – but not much meaningful change. Respondents viewed Cuba more favorably than they did in the past, perhaps a result of the restoration of full relations with Cuba starting in December 2014. And Americans viewed the Philippines much less favorably than they did three years ago, maybe a consequence of the brutal antidrug campaign of its president, Rodrigo Duterte, and strained diplomatic relations after Mr. Duterte referred to President Obama with an expletive. Russia, too, has moved relatively significantly, particularly for Republicans, who see it as less of an enemy now than they did three years ago.

Below, the survey responses for all places respondents were asked to rate.

In 2017 In 2014 Everyone Democrats Republicans Everyone Democrats Republicans