Message Boards Message Boards

GeoRegionValuePlot with a custom color function?

I used unscaled coordinates with a custom color function to visualize data for life expectancy in African countries (see code below). Five intervals for five colors. But it seems tha WM choses the boundaries of the intervals somehow different. What's the problem? Thanks!

GeoRegionValuePlot[
EntityClass["Country", "Africa"] -> "LifeExpectancy", 
ColorFunctionScaling -> False, 
ColorFunction -> (Which[70 < #, Pink, 65 < # <= 70, Blue, 
60 < # <= 65, Green, 55 < # <= 60, Gray, 50 < # <= 55, 
Orange] &), ImageSize -> 350, 
GeoLabels -> ((Tooltip[#1, Row[{#2, Spacer[5], #4}]] &))]
POSTED BY: Gregory Fridman
3 Replies
Posted 5 years ago

Hi Gregory,

I think this is similar to this from 2016. Not sure if WRI acknowledged that it is a bug, but it is reproducible in 12.0. Please add this as an example of a longstanding unresolved issue to this post.

POSTED BY: Rohit Namjoshi

Rohit, thank you for this comment and a link. I'll append my question to "Bugs Review".list

POSTED BY: Gregory Fridman

Thanks to Lukas Lang and kglr the answer is as follows:

DownValues@System`GeoPlotsDump`iGeoRegionValuePlot = 
  DownValues@System`GeoPlotsDump`iGeoRegionValuePlot /. 
   HoldPattern@
     Rescale[#, 
      minMax : {0, 1} | PatternSequence[], {#2[[1]], Plus @@ #2}] :> 
    Rescale[#, minMax, #2];
cf = Which[70 < #, Pink, 65 < # <= 70, Blue, 60 < # <= 65, Green, 
    55 < # <= 60, Gray, 50 < # <= 55, Orange] &;
GeoRegionValuePlot[
  EntityClass["Country", "Africa"] -> "LifeExpectancy", 
  ColorFunctionScaling -> False, ColorFunction -> cf, 
  ImageSize -> 350, MissingStyle -> Red, 
  GeoLabels -> ((Tooltip[#1, Row[{#2, Spacer[5], #4}]] &)), 
  PlotLegends -> Automatic] /. _BarLegend -> BarLegend[{cf, {50, 75}}]
POSTED BY: Gregory Fridman
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