3
$\begingroup$

How can I plot different sets of coordinates with different colors? For example, the two maps below would be merged into one map, with two colors.
I'm using the commands below to create the maps below - the coordinates are comma-separated and stored in input files.

latlong = Import["cluster0.txt", "CSV"];

Graphics[{Gray,  Polygon[Map[GeoGridPosition[GeoPosition[#], "Mercator"][[1]] &, CountryData["United States", "Coordinates"], {2}]], Red,  PointSize[.01], Point /@ Map[ GeoGridPosition[GeoPosition[#], "Mercator"][[1]] &, {latlong}, {2}]}]

latlong2 = Import["cluster2.txt", "CSV"];

Graphics[{Gray,  Polygon[Map[GeoGridPosition[GeoPosition[#], "Mercator"][[1]] &, CountryData["United States", "Coordinates"], {2}]], Green,  PointSize[.01], Point /@ Map[ GeoGridPosition[GeoPosition[#], "Mercator"][[1]] &, {latlong2}, {2}]}]

enter image description here

enter image description here

(Update:) I am using Mathematica version 8 so I would prefer solutions that work with this version.

$\endgroup$
4
  • 1
    $\begingroup$ Please show the code you have so far. $\endgroup$
    – C. E.
    Mar 31, 2016 at 20:14
  • 1
    $\begingroup$ Do you have geo coordinates for points? $\endgroup$
    – BlacKow
    Mar 31, 2016 at 20:24
  • $\begingroup$ I have edited my question with the commands that I used. I have a lot of coordinates and they are stored in input files. $\endgroup$ Mar 31, 2016 at 20:50
  • 1
    $\begingroup$ So you just add Green, PointSize[.01], Point /@... to your first Graphics call, see my answer below. $\endgroup$
    – BlacKow
    Mar 31, 2016 at 20:53

2 Answers 2

4
$\begingroup$
continentalcities = CityData[{Large, "UnitedStates"}] /. {_, "Alaska" | "Hawaii", _} :> 
    Sequence[];
coords = Map[GeoGridPosition[GeoPosition[#], 
      "Mercator"][[1]]&, {CityData[#, "Coordinates"] & /@ continentalcities}, {2}];
statestocolors = Thread[CountryData["UnitedStates", "Regions"] -> 
         ColorData["GeologicAges", "ColorList"][[;; 51]]];
coordsandcolors = Transpose[{coords[[1]], continentalcities, 
         continentalcities[[All, 2]] /. statestocolors}];

Graphics[{Gray, Polygon[Map[GeoGridPosition[GeoPosition[#], "Mercator"][[1]] &, 
    CountryData["UnitedStates", "Coordinates"], {2}]], 
    PointSize[.01], {#3, Tooltip[Point[#1], #2]} & @@@ coordsandcolors}]

enter image description here

For your datasets latlong and latlong2, as noted by @BlacKow already, you can use

Graphics[{Gray, Polygon[Map[GeoGridPosition[GeoPosition[#], "Mercator"][[1]] &, 
    CountryData["United States", "Coordinates"], {2}]], PointSize[.01],
     Green, Point /@ Map[GeoGridPosition[GeoPosition[#], 
       "Mercator"][[1]] &, {latlong2}, {2}], 
     Red, Point /@ Map[GeoGridPosition[GeoPosition[#], 
       "Mercator"][[1]] &, {latlong}, {2}]}]
$\endgroup$
4
  • $\begingroup$ It worked fantastic!!! $\endgroup$ Mar 31, 2016 at 21:06
  • $\begingroup$ @kglr nice sample data :) $\endgroup$
    – BlacKow
    Mar 31, 2016 at 21:16
  • $\begingroup$ Now it's even better! Is it Friday already? $\endgroup$
    – BlacKow
    Mar 31, 2016 at 21:25
  • $\begingroup$ thank you @BlacKow. Scrolled the page too fast to notice that you already answered Thiago's specific question:) $\endgroup$
    – kglr
    Mar 31, 2016 at 21:25
3
$\begingroup$
set1 = {{38.9, -77.03}, {38.9, -87.03}};
set2 =  {{36.9, -77.03}, {33.9, -87.03}};

Graphics[#, AspectRatio -> 0.65] &@{Gray,CountryData["USA", "Polygon"], Pink, PointSize[0.01], 
Point[GeoPosition[set1]], Green, Point[GeoPosition[set2]]}

enter image description here

I'm not sure about aspect ratio... I cannot check MMA 8.0, but this should work for you

Graphics[{Gray, 
  Polygon[Map[GeoGridPosition[GeoPosition[#], "Mercator"][[1]] &, 
    CountryData["United States", "Coordinates"], {2}]], Green, 
  PointSize[.01], 
  Point /@ Map[
    GeoGridPosition[GeoPosition[#], "Mercator"][[1]] &, {set2}, {2}], 
  Pink, Point /@ 
   Map[GeoGridPosition[GeoPosition[#], 
       "Mercator"][[1]] &, {set1}, {2}]}]

Or the following will probably work too:

Graphics[#, AspectRatio -> 0.65] &@{Gray, 
  CountryData["USA", "Polygon"], Pink, PointSize[0.01], 
  Point[GeoPosition /@ set1], Green, Point[GeoPosition /@ set2]}
$\endgroup$
3
  • $\begingroup$ I'm using Mathematica 8 and your command is returning this error: Coordinate GeoPosition[{{38.9, -77.03}, {38.9, -87.03}}] should be a pair of numbers, or a Scaled or Offset form. $\endgroup$ Mar 31, 2016 at 20:59
  • $\begingroup$ I updated the answer. $\endgroup$
    – BlacKow
    Mar 31, 2016 at 21:03
  • $\begingroup$ Your 2nd command works fine on Mathematica 8, but the last code snippet doesn't work. Thank you. $\endgroup$ Apr 1, 2016 at 12:50

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.