Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

What's the code to list all the world's flags?

CountryData["G8", "Flag"]

works to get those particular flags, but what about all the world's flags?

CountryData["World", "Flag"]

(* Missing["NotApplicable"] *)

This works, but seems contrived; is there a shortcut?

CountryData[#, "Flag"] & /@ CountryData[]

More importantly, is it possible to insert the flags as ChartLabels in, say, BarChart?

EDIT:

Following up on Mr. Wizard's solution, I find that some flags, when inserted as ChartLabels, are shifted down:

chart with flag labels

The rule used to create the flags is:

# -> Image[CountryData[#, "Flag"], ImageSize -> {15, 20}] & /@ 
  CountryData[];

which is necessary in this application since the data is associated to country code.

The code to generate the bar chart is somewhat lengthy and irrelevant, but essentially, it just calls ChartLabels to insert the images.

Any idea why Philippines and United Kingdom are translated downwards?

A related question is how to rotate the flags $90^\circ$ to render the BarChart on its side.

share|improve this question
    
@J.M. thanks for the edits, but I purposely wrote UnitedKingdom without a space to match CountryData though I should have code-highlighted it. –  alancalvitti Sep 23 '12 at 17:28

3 Answers 3

up vote 8 down vote accepted

For the first try:

CountryData["Countries", "Flag"]

For the second it appears to work directly:

Mathematica graphics

share|improve this answer
    
How to control the size? For example in BarChart, if inserted directly, the flags look gigantic and overlap –  alancalvitti Sep 23 '12 at 7:16
    
@alancalvitti either resize them with the mouse (drag the orange frame handle) or apply an Image[#, ImageSize -> n] & operation or similar. Perhaps I don't understand? –  Mr.Wizard Sep 23 '12 at 7:18
    
Thanks that just about works. The issues are: flag aspect ratios differ, so it appears that specifying a constant ImageSize (or even both dimensions, ie, ImageSize->{x,y}) results in a ragged array ... Also, some flags, like Philippines and UnitedKingdom are somehow translated down by almost half the vertical spacing. –  alancalvitti Sep 23 '12 at 7:25
    
@alancalvitti if you include specific examples of that in your question I shall try to address them. –  Mr.Wizard Sep 23 '12 at 7:26
    
Added edit..... –  alancalvitti Sep 23 '12 at 7:35

Re your last two questions:

I can't reproduce the flags misalignment. All flags are shown OK in my machine

enter image description here

The other question is how to rotate the BarChart and flags.

im = Image[CountryData[#, "Flag"], ImageSize -> {15, 20}] & /@ CountryData[];

BarChart[Range[5], BarOrigin -> Left, 
 ChartLabels -> (Image[#,  ImageSize -> {15, 20}] & /@ (ImageRotate /@ (im[[180 ;; 185]])))]

Mathematica graphics

share|improve this answer

GoSquared has made available a 2400 flag icon set

enter image description here

https://www.gosquared.com/resources/2400-flags

Here is how you can quickely grab the 64px versions:

flags = Import["http://www.gosquared.com/download/pixels/flags.zip", 
   "flags/64/*.png"];
countries = 
 StringDrop[#, 9] & /@ (Rest@
    DeleteDuplicates[
     StringCases[#, "flags/64/" ~~ __] & /@ 
      Import["http://www.gosquared.com/download/pixels/flags.zip", 
       "FileNames"]])
CreateDirectory[
 FileNameJoin[{$UserDocumentsDirectory, "Flags64pxPNG"}]]
    MapThread[Export, {FileNameJoin[{$UserDocumentsDirectory, 
      "Flags64pxPNG", #[[1]]}] & /@ countries, flags}]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.