Home > other >  Points to flags in ggplot2
Points to flags in ggplot2

Time:03-03

I would like to change the dots in the next plot to the flag for the respective country. For this I know that geom_flag() could works, but... not for me but I got stuck with this error message:

Error in grobify(picture, x = x, y = y, width = width, height = height,  : 
  object '.flaglist' not found

This is my code:

ggplot(df, aes(lenght, Ponto.Caspian))   
 geom_point()    ggflags::geom_flag(aes(x = longitude, y = latitude 0.5, country = country))

maybe also geom_image() could work but I don't know how to link the flag with the country column...or enter image description here

This is my data: https://drive.google.com/drive/folders/1qR2mUdrpStOYBmxajc_F4nxS_qf-4bzf?usp=sharing

thanks in advance

CodePudding user response:

It seems to work for me if I convert your countries to two-character ISO codes (which is what the example at https://github.com/jimjam-slam/ggflags uses).

I also had to load the ggflags library, rather than using ggflags::geom_flag

For example, using the countrycode package:

df$iso_code <- tolower(countrycode(df$country, origin = 'country.name', destination = 'iso2c'))

ggplot(df, aes(lenght, Ponto.Caspian))   
  geom_point()  
  geom_flag(aes(x = longitude, y = latitude 0.5, country = iso_code))
  • Related