8
$\begingroup$

I have some data that is heavy tailed (density of geocoded entities), and I want to use the GeoHistogram function to plot it, but with a log scale. Data can be found here.

When plotted normally, the graph looks like this:

geoState = WolframAlpha["state of New York", "Result"];

Show[
 GeoGraphics[{GeoStyling["OutlineMap"],GeoStyling[Lighter[Orange, 0.5]],
   Opacity[0.05],EdgeForm[{Thin,Gray}],Polygon[geoState]}, 
   GeoScaleBar -> "Miles"], 
 GeoHistogram[geoData,600 sq mi, GeoBackground -> None, 
   GeoRangePadding -> 150 Quantity[1, "Kilometers"], 
   ColorFunction -> "TemperatureMap", PlotLegends -> Automatic]
]

enter image description here

I would like a Log10 scale for the bin height (hspec). The function description for GeoHistogram says that the format GeoHistogram[*data, bspec, hspec]* should work. I can't seem to find the proper format for hspec to get log-scaled bin heights.

I have tried "Log",, {"Log", 20}, and Log10[#]& with no joy. The documentation lists the syntax as GeoHistogram[*locs*,*bspec*,*hspec*] with the following options for *hspec*: "Count", "probability", "Intensity", "PDF", and fh, but does not specify the form of fh. Taking an example from Histogram and defining fh[bins_,counts_]:=Log10[counts_] does not work either. Unlike the Histogram function, the GeoHistogram hspec documentation does not list the form of {"Log",hspec} or option of "LogCounts".

$\endgroup$
  • 2
    $\begingroup$ I think this is a bug. $\endgroup$ – chuy Aug 29 '16 at 22:05
  • $\begingroup$ Is it sufficient to have them colored appropriately? $\endgroup$ – rcollyer Sep 1 '16 at 20:53
  • $\begingroup$ They should be colored appropriately and the scale bar labeled correctly. $\endgroup$ – GraphMan Sep 1 '16 at 21:51
  • 1
    $\begingroup$ Please provide sample data for geoState and geoData. $\endgroup$ – bbgodfrey Sep 1 '16 at 22:50
  • 1
    $\begingroup$ My reading of the documentation is that hspec takes two arguments. You might try something like Log10[#2] & or Log10[Last@#] & $\endgroup$ – bbgodfrey Sep 2 '16 at 0:27
7
+50
$\begingroup$

This is a bit of a hack but you may be able to get what you want down this path. Instead of taking the Log10 of the data I'll try to change the color scale via the ColorFunction

The base for the color function

Clear[cf]
cf[x_, min_, max_] := (Log10[x] - Log10[min])/(
 Log10[max] - Log10[min]);

I use the function with the ColorFunction option

min = 1;
max = 2000;
steps = Round[10^#  & /@ Subdivide[Log10[min], Log10[2 max], 10]];
obj = GeoHistogram[geoData, Quantity[600, ("Miles")^2], 
GeoBackground -> None, 
GeoRangePadding -> 150 Quantity[1, "Kilometers"],
ColorFunctionScaling -> False,
ColorFunction -> 
Function[{z}, ColorData["TemperatureMap"][cf[z, min, max]]],
 PlotLegends -> BarLegend[{
 Function[{z}, ColorData["TemperatureMap"][cf[z, min, max]]], {min,
  max}},
  steps]]

enter image description here

You will want to play with the min and max values and possibly hand edit your steps for the scale.

$\endgroup$
  • $\begingroup$ Very close! I still would like the scale to be something like {1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000} and log spaced. I am also trying to check that the color bar scaling reflects the bin values. Hard, since I can't extract the actual bin counts from the graph. $\endgroup$ – GraphMan Sep 3 '16 at 5:06
  • $\begingroup$ You can hand edit the steps array to have whatever numbers you want. To validate you can use the color scale "Rainbow" and check the popup numbers against the scale. $\endgroup$ – c186282 Sep 3 '16 at 11:02
4
$\begingroup$

Modification of c186282's answer that shows Log10 scaling, with custom step intervals given, intermediate tics, and use of Blend to specify custom color function.

geoState = WolframAlpha["state of New York", "Result"];

cf3 = Function[{z}, 
      Blend[{Lighter[Blue, 0.9], Lighter[Blue, 0.6], Red, Yellow}, 
      cf[z, min, max]]];

decades = 4;
min = 1;
max = 10^decades;

steps = Sort[Flatten[{#* 10^Range[min - 1, decades] & /@ {1, 5}}]];

plt = GeoHistogram[geoData, Quantity[600, ("Miles")^2], "Count", 
       GeoBackground -> None, 
       GeoRangePadding -> 150 Quantity[1, "Kilometers"], 
       ColorFunctionScaling -> False, ColorFunction -> cf3, 
       PlotLegends -> BarLegend[{cf3, {min, max}}, steps]];

Show[GeoGraphics[{GeoStyling["OutlineMap"], GeoStyling[White], 
       EdgeForm[{Black, Gray}], Polygon[geoState]}, 
      GeoScaleBar -> "Miles"], plt]

Which gives the following plot:

enter image description here

I have verified that this is working with "Counts". If you change to another geo-bin value (e.g. "Intensity"), the color scale {min,max} needs to be re-calibrated.

So, the bounty goes to c186282. Many thanks!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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