4
$\begingroup$

I am making maps of stuff like population density and would like to add labels but GeoLabels makes it awfully busy. Here is an example. I would like to be able to control what gets written, the color, the location. In the following I plot the population density for each county in New Mexico. GeoLabels makes black labels that say stuff like: "Santa Fe County, New Mexico, United States" which is a tad superfluous. I'd prefer it just said "Sante Fe".

Side comment:

I've learned an enormous amount from this site and appreciate it. I'm wondering whether you wizards would've used MapThread the way I did in the call to GeoRegionValue or if you'd have done it some other way. I'm a little slow grocking functional programming.

nmcounties = AdministrativeDivisionData[Entity["AdministrativeDivision", {"NewMexico", "UnitedStates"}], "Subdivisions"];
nmpopdensity =   AdministrativeDivisionData[#, "PopulationDensity"] & /@ nmcounties;
GeoRegionValuePlot[MapThread[Rule, {nmcounties, nmpopdensity}],  ColorFunction -> ColorData["Rainbow"]]
GeoRegionValuePlot[MapThread[Rule, {nmcounties, nmpopdensity}],  ColorFunction -> ColorData["Rainbow"], GeoLabels -> True]
$\endgroup$
  • $\begingroup$ Not to be pedantic, but in the 10 months you've been a member of this site, you've accepted the answer to one of your questions, once. Did none of those answers serve your needs? If they didn't, did you make clarifications? Or, otherwise try to engage the answerers? If not, why not? $\endgroup$ – rcollyer Jan 20 '15 at 14:23
  • $\begingroup$ Oops. Sorry. I didn't know there was anything I should have been doing other than up-voting the answers. I've accepted this answer and will try to find my other questions and accept their answers as well. $\endgroup$ – JEP Jan 20 '15 at 15:25
  • $\begingroup$ Not necessarily a big deal. I just commented to nudge you in the right direction. I, too, have some questions that I have not accepted answers on, but they should be kept to a minimum. Also, I had not intended it as a push to have my answer accepted, so thank you. $\endgroup$ – rcollyer Jan 20 '15 at 15:46
9
$\begingroup$

This required a bit more work than I initially anticipated. To your second question first, per the documentation, GeoRegionValuePlot is quite versatile in what it accepts, and when you are working with a common, queryable propery, you should use the form

GeoRegionValuePlot[enityList -> "property"]

or

GeoRegionValuePlot[EntityClass -> "property"]

as it simplifies what you need to do considerably. So, you could use

GeoRegionValuePlot[
  AdministrativeDivisionData[
    Entity["AdministrativeDivision", {"NewMexico", "UnitedStates"}]
    , 
    "Subdivisions"] -> "PopulationDensity"]

But, I'm partial to the more queryable form

GeoRegionValuePlot[
  Entity["AdministrativeDivision", {_, "NewMexico", "UnitedStates"}}] ->
   "PopulationDensity"]

On to the actual question. According to the GeoLabels documentation, the function form of GeoLabels accepts 4 parameters which are polygon, entity, position, and data. So, we need to use this function:

Function[{polygon, entity, pos, data}, 
 {polygon, Black, Text[StringSplit[CommonName@entity, {",", " County"}][[1]], pos]}
]

which results in

enter image description here

$\endgroup$
3
$\begingroup$

An alternate approach is to truncate the labels. However, this does not center the labels.

nmcounties = 
  AdministrativeDivisionData[
   Entity["AdministrativeDivision", {"NewMexico", "UnitedStates"}], 
   "Subdivisions"];

nmpopdensity = 
  AdministrativeDivisionData[#, "PopulationDensity"] & /@ nmcounties;

Note that you can only need Thread with Rule:

GeoRegionValuePlot[Thread[nmcounties -> nmpopdensity], 
   ColorFunction -> ColorData["LightTemperatureMap"], GeoLabels -> True] /.
  str_String?(StringLength[#] > 34 &) :> StringDrop[str, -34] // Quiet

enter image description here

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