President Trump has rankled numerous foreign leaders during his first weeks in office. Some of these were leaders in countries Americans understand to be foes of the United States, such as Iran. But the list also includes many countries that Americans recognize as friends, such as Australia, Germany and the United Kingdom. The speaker of the British House of Commons went as far as to say that he strongly opposes letting Trump address Parliament during a state visit. Others responded satirically.

How well do Americans understand who are the nation’s friends and foes in international affairs? Not too badly, it turns out.

The polling organization YouGov asked 7,150 Americans between Jan. 28 and Feb. 1 to assess a random selection of 15 of 144 countries. The response options were “Ally,” “Friendly,” “Unfriendly,” “Enemy” or “Not Sure.” The horizontal axis on the graph below shows the percentage of Americans who selected “Ally” or “Friendly” minus “Unfriendly” and “Enemy.” I only plotted those countries about whom less than 40 percent of respondents confessed that they were “Not Sure.” For instance, 68 percent of respondents admitted that they didn’t really know whether Suriname is a country that’s friendly or unfriendly to the United States.

The vertical axis reflects how often the country voted with the United States in the United Nations General Assembly on contentious issues during the 71st session (fall of 2016). No single measure can fully capture something as complex as the degree to which two states share foreign policy orientations. But voting agreement in the U.N. is a popular indicator among academics and policymakers. For example, the State Department puts out a congressional report each year that details countries’ voting records. This report informs important policy decisions, such as foreign aid allocations.

You can think of countries above the plotted line as countries that vote more often with the United States in the United Nations than would be predicted by how friendly the American public thinks these countries are. Conversely, countries below the line vote very little with the United States compared with how friendly the U.S. public thinks these countries are. (A quadratic regression line fits the data a little better but doesn’t substantively change the insights.)

Overall, the public does pretty well. The correlation between public opinion and U.N. voting behavior is quite high (0.47).

There isn’t strong evidence that Americans harbor a bias toward nations that are predominantly Muslim. True, many of the countries that the public thinks are unfriendly to the United States have Muslim-majority populations. But the public also rates other Muslim-majority countries as quite friendly to the United States, most notably Indonesia, Morocco and Jordan. Turkey has a negative public image compared with how much it votes with the United States. That may well be based on news reports about its authoritarian turn after the recent failed coup attempt.

The idea that the BRICS countries (Brazil, Russia, India, China and South Africa) are somehow challenging the U.S. role in the world clearly hasn’t caught on with the American public. They rate Russia and (to a lesser degree) China unfavorably. But the American public thinks pretty favorably of Brazil, India and South Africa, even though they don’t vote often with the United States. One issue is that developing countries often vote together in blocs. This may make some developing countries seem less closely aligned with the United States than they would be if we used measures based solely on security issues.

Many scholars and commentators allege that the American public is ignorant about foreign affairs. That’s true by many measures. But in the aggregate, the public does have a pretty clear sense of who the United States’ foes and friends are. We will see whether that means Trump’s popularity will take a hit if he picks fights with countries the public thinks are our friends. On the other hand, Republican voters have warmed considerably toward Russian President Vladimir Putin in recent months after favorable associations with Trump. This fits academic research indicating the public doesn’t lead but follows messages by political leaders when forming opinions about foreign policy.