Group Abstract Group Abstract

Message Boards Message Boards

Coloring of country polygons based on different population values

GROUPS:
Hi everyone, I have a question concerning the coloring of polygons:
How can I color polygons (in this case a map with all the world's countries) by population/normalized levels using RGBColor[{x,0,0}]?
This is my code so far (and yes, I'm aware it's pretty bare bones and probably bad too):
Graphics[{
  EdgeForm[White],
  Black,
  Table[
   CountryData[countrie[i][/i]s[], {"SchematicPolygon", "Mercator"}],
   {i, 1, Length[countries]}
   ]
  }, ImageSize -> 800]
I already have a list of normalized population values (China being 1, India 0.896849 etc.), but I don't know how to properly implement that in the aforementioned RGBColor[].

POSTED BY: M H
Answer
6 months ago
Assuming one has already built the lists of colors and corresponding polygons, Transpose can help to match them up, as in Transpose[{listOfColors, listOfPolygons}]. Try for example the following (5 is just a random scaling factor):
With[{countries = CountryData["Asia"]},
Graphics[{EdgeForm[Black],
   Transpose[{RGBColor[5 #, 0, 0] & /@ Normalize[CountryData[#, "Population"] & /@ countries, Max],
     CountryData[#, {"SchematicPolygon", "Mercator"}] & /@ countries}]}]]
POSTED BY: Ilian Gachevski
Answer
6 months ago
For a nice color contrast you need to adjust somehow for the drastic differences between countries' populations. You could do something like the following (where "tone" is control to affect the color contrast):
 Manipulate[
  Graphics[{
      EdgeForm[Gray],
      ColorData[gradients][(CountryData[#, "Population"]/maxpop)^s],
      CountryData[#, {"SchematicPolygon", "Mercator"}]
      } & /@ CountryData[]
   , ImageSize -> 400]
  , {{s, .3, "tone"}, .01, 1}
  , {{gradients,
   "Rainbow"}, (# ->
      Show[ColorData[#, "Image"], ImageSize -> 100]) & /@
   ColorData["Gradients"]},
Initialization :> (maxpop =
    CountryData[#, "Population"] & /@ CountryData[] // Max),
SaveDefinitions -> True]




for more sophisticated code please check out these Demonstrations:



POSTED BY: Vitaliy Kaurov
Answer
6 months ago