Creating Maps with SAS/GRAPH

Download Report

Transcript Creating Maps with SAS/GRAPH

Creating Maps with
SAS/GRAPH
- Drill Downs, Pop-Ups, and
Animation
Creating Maps with SAS/GRAPH
Today’s talk
•
•
•
•
•
•
Basic capabilities of PROC GMAP
Knowledge of SAS map data sets
Colors and gray scales for choropleth maps
Outline map
Direct a graphics output to GIF and PDF files;
New features: drill-downs, pop-ups, and
animation.
Creating Maps with SAS/GRAPH
QUICK LOOK AT BASICS
• STATIC DISPLAYS
FOUR MAP TYPES
• DRILL-DOWNS
• POP-UPS
• ANIMATION
CHOROPLETH
PRISM
BLOCK
SURFACE
Creating Maps with SAS/GRAPH
DATA SETS USED
1. CANADIAN POPULATION
SOURCE: STATISTICS CANADA
2. Data sets that define the boundaries of areas
that are mapped.
SAS/GRAPH provides map data sets that allow one to create
one or more maps of nearly every country in the world. All the
maps are located in a MAPS subdirectory under the SAS root
directory. Note, SAS/GRAPH maps must be installed to use the
SAS-supplied maps.
Creating Maps with SAS/GRAPH
EXAMPLE 1: CHOROPLETH MAP
Creates two-dimensional maps in which
values of the specified response
variables are represented by varying
patterns and colors.
Creating Maps with SAS/GRAPH
EXAMPLE 1: CHOROPLETH MAP
Production of a map with the GMAP procedure requires both a response
and a map data set.
• SAS-SUPPLIED MAP OF CANADIAN PROVINCES (MAP)
contains the information needed to draw map
boundaries.
• 2001 POPULATION DATA (RESPONSE)
Contains the data that are to be displayed in a map.
• MATCH MAP AND RESPONSE DATA SETS
COMMON VARIABLE
SAME NAME, SAME TYPE
SIMILAR TO DATA STEP MERGE
Creating Maps with SAS/GRAPH
•
2001 POPULATION DATA: produces a map of the distribution of population
data canada_pop;
Input province: $2. province_name & : $21. pop_2001: comma.;
Label pop_2001 = 'POPULATION 2001‘ ;
format pop: area: comma10.;
datalines;
10 NEWFOUNDLAND
512,930
11 PRINCE EDWARD ISLAND 135,294
12 NOVA SCOTIA
908,007
13 NEW BRUNSWICK
729,498
24 QUEBEC
7,237,479
35 ONTARIO
11,410,046
46 MANITOBA
1,119,583
47 SASKATCHEWAN
978,933
48 ALBERTA
2,974,807
59 BRITISH COLUMBIA
3,907,738
60 YUKON
28,674
61 NORTHWEST TERRITORIES 64,105;
run;
Creating Maps with SAS/GRAPH
EXAMPLE 1: CHOROPLETH MAP
goptions reset=all;
title 'CANADIAN POPULATION BY PROVINCE, 2001';
footnote j=r 'EX01.SAS ';
proc gmap data=canada_pop map=maps.canada2;
id province;
choro pop_2001; /*specifies the variable that are represented on the map */
run;
quit;
title;
footnote;
Creating Maps with SAS/GRAPH
Creating Maps with SAS/GRAPH
EXAMPLE 1: CHOROPLETH MAP
goptions reset=all;
title 'CANADIAN POPULATION BY PROVINCE, 2001';
footnote j=r 'EX01.SAS ';
proc gmap data=canada_pop map=maps.canada2;
id province;
choro pop_2001 / levels=3; /*control the number of colors*/
run;
quit;
title;
footnote;
Creating Maps with SAS/GRAPH
Creating Maps with SAS/GRAPH
EXAMPLE 1: CHOROPLETH MAP
goptions reset=all;
title 'CANADIAN POPULATION BY PROVINCE, 2001';
footnote j=r 'EX01.SAS ';
proc gmap data=canada_pop map=maps.canada2;
id province;
/*control the number of color: the number of response levels */
choro pop_2001 / discrete; *format pop_2001 popfmt.;
run;
quit;
title;
footnote;
Creating Maps with SAS/GRAPH
Creating Maps with SAS/GRAPH
EXAMPLE 1: CHOROPLETH MAP
• USE FEW OPTIONS
DEFAULT PATTERN
SAS automatically determines the midpoints and assigns patterns to the map
areas.
LEVELS OPTION
DISCRETE OPTION + USER-WRITTEN FORMAT
LEGEND
the CHORO statement produces a legend unless you use the NOLEGEND option
or user-defined legend.
Creating Maps with SAS/GRAPH
EXAMPLE 1: CHOROPLETH MAP
NOTICE
• FONTS
• DEFAULT COLOR SELECTION
• POSITION AND LAYOUT OF LEGEND
(Nunavut is not shown separated from the Northwest Territories since
current SAS/GRAPH maps of Canada contain no boundary definitions
for Nunavut.)
Creating Maps with SAS/GRAPH
EXAMPLE 2
PRISM MAP (same data)
• Creates three-dimensional prism maps in
which levels of magnitude of the specified
response variables are represented by
polyhedrons (raised polygons) of varying
height, pattern, and color.
Creating Maps with SAS/GRAPH
EXAMPLE 2
PRISM MAP (same data)
goptions reset=all;
title 'CANADIAN POPULATION BY PROVINCE, 2001';
footnote j=r 'EX02.SAS ';
proc gmap data=canada_pop map=maps.canada2;
id province;
prism pop_2001; /*specifies the variable that are represented on the map */
run;
quit;
title;
footnote;
Creating Maps with SAS/GRAPH
Creating Maps with SAS/GRAPH
EXAMPLE 2
PRISM MAP (same data)
goptions reset=all;
title 'CANADIAN POPULATION BY PROVINCE, 2001';
footnote j=r 'EX02.SAS ';
proc gmap data=canada_pop map=maps.canada2;
id province;
/* change the viewing angle of the map */
prism pop_2001 / zview=10.0 yview=-3.0 xview=-5.0;
run;
quit;
title;
footnote;
Creating Maps with SAS/GRAPH
EXAMPLE 2 :
•
PRISM MAP
CHANGE VIEWING ANGLE
The XVIEW, YVIEW, and ZVIEW specify the viewing position
coordinates for the map.
The XVIEW, YVIEW, and ZVIEW options on the RISM statement
change the viewing position from the default value of a position
above and to the south of the center of the map (values of .5, 2.0, and 3.0 for the x, y, and z views respectively).
Creating Maps with SAS/GRAPH
Creating Maps with SAS/GRAPH
EXAMPLE 2
PRISM MAP (same data)
goptions reset=all;
title 'CANADIAN POPULATION BY PROVINCE, 2001';
footnote j=r 'EX02.SAS ';
proc gmap data=canada_pop map=maps.canada2;
id province;
/* change the viewing angle of the map and light source */
prism pop_2001 / zview=10.0 yview=-3.0 xview=-5.0 ylight=2;
run;
quit;
title;
footnote;
Creating Maps with SAS/GRAPH
EXAMPLE 2 :
•
PRISM MAP
CHANGE LIGHT SOURCE
XLIGHT, YLIGHT specify the coordinates of the imagined light
source in the map coordinate system. The position of the light
source controls the appearance of the edges of the map areas.
The XLIGHT= and YLIGHT= options are used to shadow the
side polygons of the prisms.
Creating Maps with SAS/GRAPH
Creating Maps with SAS/GRAPH
EXAMPLE 2 : PRISM MAP
NOTICE
• USING TWO FEATURES TO CONTRAST MAP
AREAS - COLOR AND PRISM HEIGHT (GOOD IDEA?)
• MIGHT HAVE TO ADJUST VIEWING ANGLE
TO MAKE ALL MAP AREAS VISIBLE
Creating Maps with SAS/GRAPH
EXAMPLE 3:
BLOCK MAP
Creates three-dimensional block maps on
which levels of magnitude of the specified
response variables are represented by
blocks of varying height, pattern, and color.
Creating Maps with SAS/GRAPH
EXAMPLE 3
BLOCK MAP (same data)
*** reset all graphics options to default values;
options reset=all;
*** create a block map with a title and a footnote;
title 'CANADIAN POPULATION BY PROVINCE, 2001';
footnote j=r 'EX03.SAS ';
proc gmap data=canada_pop map=maps.canada2;
id province;
block pop_2001;
run;
quit;
title;
footnote;
Creating Maps with SAS/GRAPH
Creating Maps with SAS/GRAPH
EXAMPLE 3
BLOCK MAP (same data)
*** reset all graphics options to default values;
options reset=all;
*** create a block map with a title and a footnote;
title 'CANADIAN POPULATION BY PROVINCE, 2001';
footnote j=r 'EX03.SAS ';
pattern1 v=s c=red r=12;
pattern2 v=ms c=green;
proc gmap data=canada_pop map=maps.canada2;
id province;
block pop_2001 / levels=12 shape=cylinder blocksize=5
xview=1.8 yview=-1.2 zview=1.0
nolegend coutline=black;
run;
quit;
title;
footnote;
Creating Maps with SAS/GRAPH
Creating Maps with SAS/GRAPH
EXAMPLE 3:
•
BLOCK MAP
PATTERN statements
create PATTERN definitions that define the color and type of area fill for
patterns used in map areas in choropleth, block, and prism maps;
blocks in block maps.
COLOR=pattern-color
VALUE=block/map-pattern
•
•
block-pattern: EMPTY / SOLID
map-pattern: MEMPTY / MSOLID
REPEAT=number-of-times
specifies the number of times that a PATTERN definition is applied before
the next PATTERN definition is used. By default, REPEAT=1.
Creating Maps with SAS/GRAPH
EXAMPLE 3:
•
BLOCK MAP
PATTERN statements
Generating Pattern Sequences
pattern1 v=s c=red r=12;
pattern2 v=ms c=green;
–
•
specifying that all blocks are red (12 provinces) and that the map areas are
green.
Options used on the BLOCK statement
–
–
–
–
–
Twelve different levels are requested (one per province).
The shape and size of the blocks are changed. Just as was done with the
PRISM map, the viewing angle is changed.
The block height, not color, displays population information.
The legend is suppressed (NOLEGEND).
By default, the map areas are outlined in their own color (in this example, green)
so the COUTLINE option is used to specify a color for provincial boundaries.
Creating Maps with SAS/GRAPH
EXAMPLE 3:
BLOCK MAP
NOTICE
• LEVELS OPTION + PATTERN STATEMENTS
• CHANGE VIEWING ANGLE
• CHANGE BLOCK SHAPE AND SIZE
Creating Maps with SAS/GRAPH
EXAMPLE 4 SURFACE MAP
Creates three-dimensional surface
maps in which levels of magnitude of
the specified response variables are
represented by spikes of varying height.
Creating Maps with SAS/GRAPH
EXAMPLE 4 SURFACE MAP
*** reset all graphics options to default values;
goptions reset=all;
*** create a surface map with a title and footnote;
title 'CANADIAN POPULATION BY PROVINCE, 2001';
footnote j=r 'EX04.SAS ';
proc gmap data=canada_pop map=maps.canada2;
id province;
surface pop_2001;
run;
quit;
title;
footnote;
Creating Maps with SAS/GRAPH
Creating Maps with SAS/GRAPH
EXAMPLE 4 SURFACE MAP
*** reset all graphics options to default values;
goptions reset=all;
*** create a surface map with a title and footnote;
title 'CANADIAN POPULATION BY PROVINCE, 2001';
footnote j=r 'EX04.SAS ';
proc gmap data=canada_pop map=maps.canada2;
id province;
surface pop_2001 / rotate=80 tilt=45 nlines=100 constant=30 cbody=red;
run;
quit;
title;
footnote;
Creating Maps with SAS/GRAPH
Creating Maps with SAS/GRAPH
EXAMPLE 4 SURFACE MAP
Using a spike at the center of each map area displays map data. The height of
the spike shows relative values of population. The map is intended to show a
gradient in population rather than exact values.
• ROTATION , TILT options rotate the map about the z-axis and x-axis
respectively (the default is 70 degrees for both options).
• NLINES option controls the number of lines used on the map surface
(default 50, range 50-100).
• CONSTANT controls the appearance of the spikes (both width and
height). By default, constant=10...Values greater than 10 yield spikes
that are wider at the base. Values less than 10 yield spikes that are
narrower at the base...
• CBODY specifies the color that is used to draw the surface map.
Creating Maps with SAS/GRAPH
EXAMPLE 4 SURFACE MAP
NOTICE
• NO LEGEND
• EFFECT OF VARIOUS OPTIONS
• LIMITED USE OF COLOR (CBODY
OPTION)
Creating Maps with SAS/GRAPH
SAS-SUPPLIED MAP DATA SETS
As stated earlier, SAS/GRAPH provides map data sets that allow one
to create one or more maps of nearly every country in the world.
At a minimum, a map data set contains three variables:
• X and Y
(both numeric) that contain the coordinates of map areas (commonly,
but not necessarily longitude and latitude);
• ID
a variable that contains a value for the geographic area associated
with each pair of X-Y variables.
Creating Maps with SAS/GRAPH
SAS-SUPPLIED MAP DATA SETS
Two other variables that may be present:
• SEGMENT is used by the GMAP procedure to draw map areas that
may comprise more than one polygon.
• DENSITY can be used to reduce the number of X-Y coordinates
used to draw map boundaries when less detailed maps are
permissible.
Creating Maps with SAS/GRAPH
SAS-SUPPLIED MAP DATA SETS
• SPECIAL DATA SET (METAMAPS)
a data set with information about maps in the SAS library.
*** display a list of maps in the MAPS library for Canada***;
proc print data=maps.metamaps label;
var country memname;
where memtype eq 'DATA' and type eq 'GRAPH' and country = 'CANADA';
run;
Creating Maps with SAS/GRAPH
SAS-SUPPLIED MAP DATA SETS
• SPECIAL DATA SET (METAMAPS)
Name of
Country
CANADA
CANADA
CANADA
CANADA
CANADA
Library
Member
Name
CANADA
CANADA2
CANADA3
CANADA4
CANCENS
Creating Maps with SAS/GRAPH
SAS-SUPPLIED MAP DATA SETS
•
Four map data sets for Canada:
CANADA, CANADA2 draw maps of census districts within Canadian provinces.
CANADA3, CANADA4 draw maps of Canadian provinces
•
The data set CANCENS contains information about map areas:
–
province numbers and names
–
region numbers and names
CREATE MAPS FROM SHAPEFILES (V9)
version 9 has a new procedure, PROC MAPIMPORT, that allows one
to convert shapefiles to map data sets.
Creating Maps with SAS/GRAPH
PROJECTED AND UNPROJECTED MAP DATA SETS
Contents of CANADA2 and CANADA4 Map Data Sets
*******CANADA2 - 4,302 observations
# Variable
Type
Len
1 PROVINCE
Char
2
2 SEGMENT
Num
5
3 X
Num
6
4 Y
Num
6
Label
Province Abbreviation
Province Segment Number
X Coordinate
Y Coordinate
******* CANADA4 - 31,311 observations
# Variable
Type
Len
2 DENSITY
Num
5
1 PROVINCE
Char
2
3 SEGMENT
Num
5
4 X
Num
6
5 Y
Num
6
Label
Density for Lower Resolution Maps
Province Abbreviation
Province Segment Number
Unprojected Longitude in Radians
Unprojected Latitude in Radians
There are two differences: CANADA4 contains over seven times the number of X-Y
coordinates as CANADA2; CANADA4 coordinates are unprojected.
Creating Maps with SAS/GRAPH
Creating Maps with SAS/GRAPH
Creating Maps with SAS/GRAPH
PROJECTED AND UNPROJECTED MAP DATA SETS
There are several notable differences between the output of two maps:
• the map is backwards;
• the shape is distorted;
• there is much more detail in the map boundaries.
Another SAS/GRAPH procedure must be used prior to PROC GMAP to
project the unprojected map coordinates.
*** project the CANADA4 map data set;
proc gproject data=maps.canada4 out=c4_projected;
id province;
run;
Creating Maps with SAS/GRAPH
PROJECTED AND UNPROJECTED MAP DATA SETS
NOTICE
• VARIABLES (LABELS)
• NUMBER OF OBSERVATIONS
Creating Maps with SAS/GRAPH
User-Defined COLORS AND GRAY SCALES
IN CHOROPLETH MAPS
• PATTERN STATEMENT
USER-DEFINED COLOR SCHEME
http://www.colorbrewer.com
*** choose a set of colors - sequentially increasing shades of blue;
pattern1 v=ms c=cxeff3ff;
pattern2 v=ms c=cxbdd7e7;
pattern3 v=ms c=cx6baed6;
pattern4 v=ms c=cx2171b5;
• LEGEND STATEMENT
*** specify parameters for the legend;
legend1origin=(75,60)pct across=1 mode=share
label=(position=top j=c 'POPULATION PER' j=c 'SQUARE KILOMETER')
shape=bar(3,4)pct cborder=blue;
Creating Maps with SAS/GRAPH
Creating Maps with SAS/GRAPH
Creating Maps with SAS/GRAPH
Create an Outline Map of British Columbia
with Census Districts
When a map showing only map boundaries (no data) is needed.
• USE MAP DATA SET AS RESPONSE DATA SET (ALL OPTION)
• USE UNPROJECTED MAP DATA SETS (Canada3)
• Only one observation need be used for the response data set.
Creating Maps with SAS/GRAPH
Create an Outline Map of British Columbia with Census Districts
*** reset all graphics options to default values;
goptions reset=all;
proc gproject data=maps.canada3 out=BC;
where province eq '59';
id cdcode;
run;
pattern v=me;
title 'BRITISH COLUMBIA REGIONS';
footnote j=r 'EX14.SAS ';
proc gmap data=BC (obs=1) map=BC all;
id cdcode;
choro cdcode / nolegend;
run;
quit;
title;
footnote;
Creating Maps with SAS/GRAPH
Creating Maps with SAS/GRAPH
ALTERNATIVE OUTPUT DESTINATIONS
The file can easily be posted on the web or incorporated into other programs (e.g. PowerPoint).
• GIF (FILENAME STATEMENT)
goptions reset=all
device=gif
/* select the GIF device driver*/
gsfname=mapout /* specify a FILEREF for the GIF file */
ftext='Arial/bo‘
/* select a font */
xpixels=800
/* map size */
ypixels=600
/* map size */;
filename mapout ‘C:\My sas maps\map1.gif';
• PDF (ODS)
goptions reset=all ftext='Helvetica/bo‘ rotate=landscape;
ods pdf file= ‘C:\my sas maps\map1.gif ' notoc;
......
ods pdf close;
Creating Maps with SAS/GRAPH
NEW FEATURES
allow for the creation of maps with dynamic features:
• Drill Downs
map areas can be hyperlinked to additional information;
• Pop-Ups
additional information can be provided to map users
when a mouse cursor passes over a map area;
• Animation
a time dimension can be added using animation. (many
gif files, layered into one file)