BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mcs
Obsidian | Level 7 mcs
Obsidian | Level 7

I'm just starting out with PROC SGMAP.  I want to learn how to make a bubble plot.  I tried the following code.

 

proc sort data=sashelp.us_data(keep=population_2010 state) out=us_pop;
by state;

data us_pop;
merge us_pop mapsgfk.uscenter(keep=lat long state);
by state;

proc sgmap maprespdata=us_pop mapdata=mapsgfk.us;
choromap population_2010 / mapid=state;
run;

proc sgmap plotdata=us_pop mapdata=mapsgfk.us;
choromap / mapid=state;
bubble x=long y=lat size=population_2010;
run;

The first map worked fine, but the second one showed only the bubbles and no state outlines.

choro.png

bubble.png

What did I do wrong?

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Check your map data set. My version of mapsgfk.US does not have lat and long coordinates.

 

If that is the case with yours then the plotdata does not correspond to the mapdata for geographic coordinates. Then the "map" created shows the bubbles over a likely squarish region using the lat/long as simple cartesian coordinates.

View solution in original post

7 REPLIES 7
ballardw
Super User

Check your map data set. My version of mapsgfk.US does not have lat and long coordinates.

 

If that is the case with yours then the plotdata does not correspond to the mapdata for geographic coordinates. Then the "map" created shows the bubbles over a likely squarish region using the lat/long as simple cartesian coordinates.

mcs
Obsidian | Level 7 mcs
Obsidian | Level 7

Thanks for your help.  I tried using mapsgfk.uscenter (which has lat and long) for the mapdata= option, but that didn't work for either the choro or the bubble.  What are my options for mapdata=?

 

ballardw
Super User

@mcs wrote:

Thanks for your help.  I tried using mapsgfk.uscenter (which has lat and long) for the mapdata= option, but that didn't work for either the choro or the bubble.  What are my options for mapdata=?

 


The two basic approaches are to find a map data set with lat long for the polygon borders or project your lat long to an X Y coordinate system that matched your map data coordinate system.

 

You might look at using the Mapsgfk.Us_all for the map data set. It has Lat and Long values.

 

Warning: depending on your data and the mapdata set you may have east/west values reversed. The "traditional" longitude used E and W to indicate which way the value is from the prime meridian. If your value is positive for Long in the US then it will be treated as "east" instead of "west" which will again be out of scope with the map data. If this happens try multiplying your Long value by -1 in a data step and see if that graphs better.

mcs
Obsidian | Level 7 mcs
Obsidian | Level 7

Thanks again.  Substituting mapdata=mapsgfk.us_all into my earlier code didn't work.  After a few more iterations, I got to mapdata=mapsgfk.us_states(where=(statecode not in ('AK','HI'))).  That's closer, but still not so good.

 

choro2.png

bubble2.png

I'm still trying to figure out how to make a bubble plot on the "standard" US map, i.e., mapsgfk.us.  

 

ballardw
Super User

That means that you are going to have to project your data from lat long to the x y coordinate system of the map data set you use.

 

This is not trivial. Do you have SAS/Graph and/ or access to proc GProject? and documentation for the procedure?

Ksharp
Super User

Calling @GraphGuy 

GraphGuy
Meteorite | Level 14

Although this one is solved, I wanted to add some explanation ...

 

mapsgfk.us is a 'special' map, which only contains projected X/Y (no unprojected long/lat) ... and Alaska & Hawaii are also moved and resized. As someone mentioned, your code was plotting the unprojected long/lat bubbles on the projected/customized US map.

 

The fix requires only a small change in your code (see code in 'bold' below) ... rather than keeping the unprojected long/lat when you merge in the uscenter, you'll want to keep the projected/modified x/y. And then use x=x and y=y in proc sgmap (rather than x=long y=lat). With this change you're *almost* there ... but the uscenter dataset has some extra obsns for label positions in the ocean, so you'll want to eliminate them (where ocean^='Y').

 

proc sort data=sashelp.us_data(keep=population_2010 state) out=us_pop;
by state;

run;

 

data us_pop;
merge us_pop mapsgfk.uscenter(keep=x y state ocean);
by state;
if ocean^='Y' then output;
run;

 

proc sgmap plotdata=us_pop mapdata=mapsgfk.us;
choromap / mapid=state;
bubble x=x y=y size=population_2010;
run;

 

us_bubble_map.png

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1155 views
  • 6 likes
  • 4 in conversation