To create a means of displaying information about the distribution of primary care providers, the population density and the average yearly Medicare expenditure per enrollee for each state, I would like to create a US map with the state boundaries indicated, and then display a tool tip box containing the data for that state when the cursor hovers over that state. CountryData["UnitedStates"] does not have a map that includes the state boundaries.

In addition, I would like to colorize the states to indicate the value of a given parameter for that state, such as age-adjusted average yearly cost per Medicare Enrollee, by reference to a color scale.

I have not been able to find the Mathematica 9 code for an interactive US map in the Mathematica demonstrations and I am interested in suggestions or working code that I could use. My level of proficiency with Mathematica 9 is somewhere between beginner and intermediate, so I appreciate the details that might not be necessary for explaining the solution to an experienced user.

  • $\begingroup$ There are three or four questions here that have tried to make USA state maps because CountryData doesn't do them. Have a search through them and see if anything gives you a starting point. $\endgroup$
    – cormullion
    Jul 29, 2013 at 21:31
  • 1
    $\begingroup$ How about this kml file? $\endgroup$ Jul 29, 2013 at 21:33
  • $\begingroup$ @SjoerdC.deVries from this question perhaps? $\endgroup$
    – cormullion
    Jul 29, 2013 at 21:35
  • $\begingroup$ @cormullion actually just from a Google search. About the 4th hit on the page. $\endgroup$ Jul 29, 2013 at 21:38
  • 1
    $\begingroup$ @bobthechemist They are in there. Look for the STATES.state.name field name. $\endgroup$ Jul 30, 2013 at 7:05

1 Answer 1


Part of the code taken from the question posted by @Cormullion

       crimestats =   WolframAlpha[   "Murder rate by state", {{"PropertyRanking:CrimeData", 1}, 
        crimestats =   MapThread[Rule, {crimestats[[All, 2]], #[[1]] & /@ crimestats[[All, 3]]}];
        usa = Import["http://code.google.com/apis/kml/documentation/us_states.kml","Data"];
        transform[s_] := StringTrim[s, Whitespace ~~ "(" ~~ ___ ~~ ")"];
        polygons =   Thread[transform["PlacemarkNames" /. usa[[1]]] -> ("Geometry" /. usa[[1]])];
        stateNames = Extract[stateNames,Position[stateNames, x_ /; x != "Alaska" && x !="Hawaii"]];
        origdata = (stateNames /. polygons)[[All, 2 ;;, 1]];
        values = stateNames /. crimestats;
        colors = Module[{val = values, min, max, int}, min = Min@val; 
                         max = Max@val; int = Floor[#/((max - min)/4)] + 1 & /@ val; 
                         ColorData[8, "ColorList"][[#]] & /@ int];
                       Table[{EdgeForm[Directive[Black, AbsoluteThickness[0.5]]], 
                       colors[[i]], Tooltip[Polygon[origdata[[i]]], 
                                         Column[{stateNames[[i]], values[[i]]}]]}, {i, Length@origdata}], 
                       AspectRatio -> Automatic, ImageSize -> Large]]
  • $\begingroup$ You're missing a preliminary definition for stateNamesstateNames = polygons[[All, 1]]; $\endgroup$
    – rm -rf
    Jul 30, 2013 at 2:51
  • $\begingroup$ @rm-rf thanks for fixing. Skipped it during cut an paste. $\endgroup$
    – Zviovich
    Jul 30, 2013 at 13:27

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.