3
$\begingroup$

I know that I can plot multiple GeoGraphics results on the same map by using something like Show[Graphics@@p1, Graphics@@p2], but it doesn't really work (seems to suffer from some kind of truncation on some parts of the second region).

On a more basic level, I want to simply colorize a map. Each region is generated in the following way:

GeoGraphics[{FaceForm[Red], 
    Normal[ds[[(Flatten@Position[fileContents, #])]][All, 
"Geometry"]]}]

Where # goes from 0 to some number inclusive. I want to show all of these regions on the map, each with their own colors (from 0 to N, I will need at least 8 different colors, it's fine if they get recycled, just not for adjacent regions (adjacency has nothing to do with the value of #)).

Is there a simple way to do this?

$\endgroup$

3 Answers 3

5
$\begingroup$

I post this example in case it is helpful:

africa = CountryData["Africa"];
col = RGBColor @@@ RandomReal[{0, 1}, {Length[africa], 3}];
GeoGraphics[
 MapThread[{EdgeForm[Red], FaceForm[#1], Polygon[#2]} &, {col, 
   africa}]]

enter image description here

$\endgroup$
5
  • $\begingroup$ This provided the seed of the answer. As an aside, how can I show labels for each region using GeoGraphics? It seems that GeoLabels is only an option for GeoListPlot and GeoRegionValuePlot? $\endgroup$
    – soandos
    Commented Feb 24, 2015 at 13:37
  • $\begingroup$ Just in case you haven't seen this new M10 function, you could do col = RandomColor[Length[africa]]; $\endgroup$
    – Greg Hurst
    Commented Feb 24, 2015 at 18:35
  • $\begingroup$ @ChipHurst thank you I did not know $\endgroup$
    – ubpdqn
    Commented Feb 25, 2015 at 12:30
  • $\begingroup$ @soandos I am sorry I am time poor at present but suspect playing you will achieve desired goal $\endgroup$
    – ubpdqn
    Commented Feb 25, 2015 at 12:32
  • $\begingroup$ It was solved thanks to you, what I actually did is below $\endgroup$
    – soandos
    Commented Feb 25, 2015 at 12:33
4
$\begingroup$

Here's a map colouring solution using the graph colouring functionality of IGraph/M.

Take the countries of Europe:

countries = CountryData["Europe"];

Build a graph based on which countries share a border.

borderingQ[c1_, c2_] := MemberQ[c1["BorderingCountries"], c2]

graph = RelationGraph[borderingQ, countries]

Mathematica graphics

Colour and plot!

GeoGraphics@MapThread[{GeoStyling[#2], Polygon[#1]} &, 
       {countries, ColorData[97] /@ IGVertexColoring[graph]}]

Mathematica graphics


The key function was:

?IGVertexColoring

IGVertexColoring[graph] returns a vertex colouring of graph.


A practical shortcoming of this graph-based map colouring method is that it doesn't make it intuitively obvious where islands belong. Iceland, the Faroese islands, Shetland, the UK, Svalbard and Norway are all blue and are all the in the same area. It is not at all clear to a reader of the map that the Svalbard belong to Norway, Shetland to the UK, and the rest are separate.

$\endgroup$
1
$\begingroup$

For completeness, here is what I ended up with:

temp = ds[[(Flatten@Position[fileContents, #1])]] & /@ (Range[
  Length[fileContents]] - 1);
GeoGraphics[
    MapThread[{GeoStyling[#1], Normal[#2[All, "Geometry"]]} &, {col, temp}]]

Using GeoStyling instead of FaceForm to make the colors much more bold.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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