DataMap is a Ruby library that represents information in maps and generate them as lots of image types, using RMagick.
The value associated to each country is mapped into one of the value ranges. Each value range has an associated color, so the country is painted with that color.
Visit the project page in Github!
You get the code by Git:
git clone git://github.com/caiosba/DataMap.git
Run the tests by:
ruby test/world_map_test.rb
You can view it here. You can also generate it using RDoc.
For the following code...
require 'data_map'
m = DataMap::WorldMap.new
m.data = {
"us" => 250,
"br" => 1254,
"ar" => 957,
"pt" => 15,
"es" => 110,
"fr" => 1398,
"au" => 341
}
m.title = "Example"
m.make_ranges_log
m.make_colors
m.map_values
m.make_legend
m.save_file "map.png", :size => '800x600>', :quality => 80
You will achieve the following image:

You can also pass some arguments in the constructor.
The example below uses another color palette and do not generates a legend.
For the output image, we choose another quality, format and size. The size string and formats are the same as RMagick. And aso outputs the image as SVG.
We can use a linear function to define the range.
require 'data_map'
m = DataMap::WorldMap.new(
:data => {
"us" => 250,
"br" => 1254,
"ar" => 957,
"pt" => 15,
"es" => 110,
"fr" => 1398,
"au" => 341
},
:palette => 'palettes/ubuntu.color'
)
m.title = "Example 2"
m.make_ranges_linear
m.make_colors
m.map_values
m.save_file "map.jpg", :size => '640x480', :quality => 90
m.save_file "map.svg"
You will achieve the following JPG image:

And the map in SVG.
For all possibilities, please see the documentation.
There is also an example inside the code. You can see it in example.rb.