# Anomalous scaling in GeoRegionValuePlot when using non-default color scheme

I found this plot online,

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"]]


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

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"]}


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


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,

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 SystemGeoPlotsDumpdefaultGeoRegionValuePlotColorFunction, 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]