Message Boards Message Boards

1
|
5434 Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Coloring of country polygons based on different population values

Posted 12 years ago
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
2 Replies
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
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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract