Message Boards Message Boards

Mapping Crime Rates in the US

POSTED BY: Bernat Espigulé

The crime rates from this Wikipedia table have been updated so the code to parse it must be adjusted:

crime2014=Import["https://en.wikipedia.org/wiki/List_of_United_States_cities_by_crime_rate_(2014)#Crime_rates_per_100.2C000_people_.282014.29","Data"][[1,1,3,All,2;;-2]];
interpreters[{city_,population_,violentCrime_,murder_,rape_,robbery_,aggravatedAssault_,propertyCrime_,burglary_,larceny_,motorVehicle_}]:={Interpreter[Restricted["City",United States (country)]][First[StringSplit[city,{"-"," *"," Metro"}]]],
Interpreter["Integer"][population],Interpreter["Number"][violentCrime],Interpreter["Number"][murder],Interpreter["Number"][rape],
Interpreter["Number"][robbery],Interpreter["Number"][aggravatedAssault],
Interpreter["Number"][propertyCrime],Interpreter["Number"][burglary],
Interpreter["Number"][larceny],Interpreter["Number"][motorVehicle]}
data=interpreters/@Drop[crime2014,1];
crime=Cases[DeleteCases[data,{_Failure,_,_,_,_,_,_,_,_,_,_}],{_,_,_Real,_Real,_Real,_Real,_Real,_Real,_Real,_Real,_Real}];
dataset14=Dataset[<|"city"->#[[1]],"population"->#[[2]],"crime"->#[[3]],"murder"->#[[4]],"rape"->#[[5]],"robbery"->#[[6]],"assault"->#[[7]],"property"->#[[8]],"burglary"->#[[9]],"larceny"->#[[10]],"vehicle"->#[[11]]|>&/@crime]

Dataset 2014

I'm attaching the new dataset and the following interactive map of the US crime rates. The markers of the major cities are colored according to the city's murder cases per 100,000 people for all of calendar year 2014, and they scale according to the city's crime rates total:

GeoGraphics[{Polygon[United States  (country)],
Tooltip[GeoMarker[#[[1]],"Scale"->Total[Take[#,3;;11]]/5000.,"Color"->ColorData["DarkRainbow"][#[[4]]/50]],Dataset[#]]&/@Normal[SortBy[dataset14,#crime&]]},
GeoRange->{{22,51},{-126,-66}},GeoProjection->"Mercator", ImageSize->600]

US Crime Rates

Attachments:
POSTED BY: Bernat Espigulé
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