当你在 R 中尝试这个时,我在 Pyhton 中有一个解决方案。您可以在 R 中使用类似的逻辑:
# Say this is your list:
countries = ['IN', 'DE', 'US', 'UK']
# Create a list of countries in different continents like this:
asia = ['IN', 'NP']
america = ['US', 'CD']
europe = ['DE', 'UK', 'FR']
# You can then map your list with these values using a definition:
for i in range(len(countries)):
if countries[i] in asia:
countries[i] = 'Asia'
elif countries[i] in america:
countries[i] = 'America'
elif countries[i] in europe:
countries[i] = 'Europe'
else:
countries[i] = 'Others'
# Now check your list
countries
['Asia', 'Europe', 'America', 'Europe']
准备好此列表后,您可以创建箱线图。
希望这可以帮助。