5
$\begingroup$

I found this plot online,

plot

and thought "I bet I could do that with a one-liner using GeoRegionValuePlot". But then it turns out that you are much better off using a log-scale because you have recognized CountryData[] entities like Macau that really wreck the color bar. How exactly to implement a log scale in this kind of plot is one matter I think I could work out, although I reckon the legend will have to be hand-built.

But I noticed on some of my tests that Greenland seemed to have an insane population density, and I was able to condense it down to a simple example:

GeoRegionValuePlot[{Entity["Country", "Greenland"] -> 1, 
  Entity["Country", "Brazil"] -> 5.5, 
  Entity["Country", "Afghanistan"] -> 20}]
GeoRegionValuePlot[{Entity["Country", "Greenland"] -> 1, 
  Entity["Country", "Brazil"] -> 5.5, 
  Entity["Country", "Afghanistan"] -> 20}, 
 ColorFunction -> ColorData["BlueGreenYellow"]]

Mathematica graphics

As you can see, the coloring works just fine when using the automatic color function, but when you supply a built-in color function (the same one that is used in the documentation) it doesn't work. In the second plot, Greenland should be the darkest color.

This gives the same problem in version 10.1 and 10.4, but version 10.0 gives the correct plot

$\endgroup$

1 Answer 1

1
$\begingroup$

There is definitely a bug in the color function rescaling of GeoRegionValuePlot. Here is an even simpler instance of the problem,

{GeoRegionValuePlot[{Entity["Country", "Greenland"] -> 1, 
   Entity["Country", "Brazil"] -> 5., 
   Entity["Country", "Afghanistan"] -> 20}, 
  ColorFunction -> "BlueGreenYellow"],
 GeoRegionValuePlot[{Entity["Country", "Greenland"] -> 0, 
   Entity["Country", "Brazil"] -> 5., 
   Entity["Country", "Afghanistan"] -> 20}, 
  ColorFunction -> "BlueGreenYellow"]}

Mathematica graphics

So if we look at the actual color function used in the version that works,

Trace[GeoRegionValuePlot[{Entity["Country", "Greenland"] -> 0, 
     Entity["Country", "Brazil"] -> 5., 
     Entity["Country", "Afghanistan"] -> 20}, 
    ColorFunction -> "BlueGreenYellow"],
   HoldPattern[ColorFunction -> _Function], TraceInternal -> True] // 
  Flatten // First

enter image description here

it says that if the value is Missing[TooLow] or is 0., then use the dark blue color, and if it is Missing[TooHigh] to use the yellow color.

Now look at the Trace output when I change the 0 above to a 1,

enter image description here

Now the color for the TooLow or 0 is set as yellow, so whichever country has the lowest value will instead default to the highest-valued color. As noted in the question, this does not occur when the default color function, aptly named System`GeoPlotsDump`defaultGeoRegionValuePlotColorFunction, is used.

A workaround is to turn off ColorFunctionScaling,

GeoRegionValuePlot[{Entity["Country", "Greenland"] -> 1, 
  Entity["Country", "Brazil"] -> 5., 
  Entity["Country", "Afghanistan"] -> 20}, 
 ColorFunction -> ColorData[{"BlueGreenYellow", {1, 20}}], 
 ColorFunctionScaling -> False]

Mathematica graphics

$\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.