300 likes | 1.12k Views
如何使用 sas map 繪製地圖. 以台灣地圖為例. 想一想如何作畫. 材料 1. 一張台灣地圖 2. 一份各地區觀測值資料 工具 GMAP procedure 表示方式 --- 平面圖 或 長方圖. Sas map data sets. default sas library : Maps Taiwan Taiwan2. 縣市為最小單位. Taiwan : Map data-set. 座標. 才能畫界線. Taiwan2 : Response data set. 以鄉鎮為最小單位. GMAP procedure.
E N D
如何使用sas map 繪製地圖 以台灣地圖為例
想一想如何作畫 • 材料 1.一張台灣地圖 2.一份各地區觀測值資料 • 工具 GMAP procedure • 表示方式---平面圖 或 長方圖
Sas map data sets • default sas library : Maps • Taiwan • Taiwan2 縣市為最小單位
Taiwan : Map data-set 座標 才能畫界線 Taiwan2 : Response data set 以鄉鎮為最小單位
GMAP procedure • Use the PROC GMAP statement to identify the map and response data sets. • Use the ID statement to name the identification variable(s). • Use a BLOCK, CHORO, PRISM, or SURFACE statement to identify the response variable and generate the map
Procedure Syntax • PROC GMAPMAP=map-data-set<DATA=response-data-set> <ALL> <ANNOTATE=Annotate-data-set> <GOUT=<libref.>output-catalog> <IMAGEMAP=output-data-set> ID id-variable(s); CHOROresponse-variable(s) </ option(s)>;BLOCKresponse-variable(s) </ option(s)>; PRISMresponse-variable(s)</ option(s)>; SURFACEresponse-variable(s) </ option(s)>;
Basic procedure Simple and Easy
choro • Creates two-dimensional maps in which values of the specified response variables are represented by varying patterns and colors. procgmap data=maps.taiwan2 map=maps.taiwan id id; choro idname/discrete coutline=black ; run; Response data set Map data-set Response var.?
block • 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. data map; set maps.taiwan2; if id in (5101520) then no=5; else if id in ( 369121518 ) then no=3; else if id in (71421) then no=7; else no=0; run; procgmap data=map map=maps.taiwan id id; block no/discrete coutline=black CBLKOUT=black ; run;
prism • 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. procgmap data=map map=maps.taiwa id id; prism no/discrete coutline=black; run;
Advance procedure ---to enhance the map Complicated and Optional
By var legend Annotate pattern
example goptions reset=all; legend1 position=( middle right inside) label=none shape=bar(1,1)pct mode=share across=1; Data citystar; ……;run; procgmap data=strata8 map=d.taiwan; by strata; id id; choro city1 city /discrete coutline=black legend=legend1 annotate=citystar; format city1 city city. strata st.; run;
Method • Goptions --- Set the graphics environment • Pattern • Legend • Annotate data set • Choro statement </options> -- appearance options -- legend options -- mapping options
Goptions --- set the graphics environment • options that affect the appearance of the display area and the graphics output • options that affect color • options that control font selection or text appearance goptions reset=global gunit=pct border cback=white colors=(black blue green red) ctext=black ftext=swiss htitle=6 htext=3;
pattern pattern1 v=ms c=LIB; pattern2 v=ms c=LIBG; V=map/plot-pattern
legend The LEGEND statement controls the location and appearance of legends on two-dimensional plots, contour plots, maps, and charts. legend1 position=( middle right inside) label=none shape=bar(1,1)pct mode=share across=1;
Annotate data set data citystar; length function style color $ 8 position $ 1 text $ 20; retain function 'label' xsys ysys '2' hsys '3' when 'a'; set xy(keep=id idname x y); if id in (305 110 111 1201 6307 1015 401 1327 1203 1214 151010031702619); /*city 為縣市代碼*/ if id>999 then city=substr(id,9,2)*1; else if id>99 then city=substr(id,10,1)*1; else city=substr(id,11,2)*1; if id^=0; /*strata 分層*/ if (id in ( 63101102103104105106110111))or (city in(63))then strata=1; if (id in (107108109112113114115116117118119 12012112212312412512612712812917)) or (city in (17))then strata=2; if (city in (34518)) then strata=3; if (city in (67819)) then strata=4; if (city in (920102111)) then strata=5; if (city in (64121316)) then strata=6; if (city in (21415)) then strata=7; style='special'; text='M'; color='red'; size=7; position='5'; output; style='KAI'; text=idname; color='yellow';size=5; position='8'; output; run;
Choro statement </options>; procgmap data=strata8 map=d.taiwan; by strata; id id; choro city1/discrete coutline=black legend=legend1 annotate=citystar; format city1 city. strata st.; run;
appearance options ANNOTATE=Annotate-data-set CEMPTY=empty-area-outline-color COUTLINE=nonempty-area-outline-color | SAME XSIZE=map-width <units> YSIZE=map-height <units
legend options CTEXT=text-color LEGEND=LEGEND<1...99> NOLEGEND
mapping options DISCRETE LEVELS=number-of-response-levels MIDPOINTS=value-list MISSING
找個例子試試看囉 The End