BookmarkSubscribeRSS Feed
Hagay
SAS Employee

בשבועות האחרונים ראינו חלק ממגוון הגרפים הקיימים ב – proc sgplot ואיך ניתן לשלב מספר סוגי גרפים בתרשים אחד.

 

לפעמים, אבל, אנחנו רוצים להוסיף את המגע האישי והמאוד ייחודי שלנו לגרף, למשל להדגיש תצפית מסוימת, להוסיף הערה מחכימה או סימון כלשהו להסב את תשומת ליבו של הקורא (צופה?).

 

בדיוק לשם כך proc sgplot כולל מנגנון שנקרא annotate שמאפשר לנו להוסיף אובייקטים שונים כחלק מהגרפים שאנחנו יוצרים. הרעיון הוא שאנחנו יוצרים טבלת SAS עם משתנים מתאימים ו – SAS משתמשת במידע שבטבלה הזאת בעת יצירת הגרף.

 

ישנן מספר סוגים של פונקציות שאנחנו יכולים להשתמש בהן כדי להוסיף מידע לגרף כגון arrow אשר מציירת חץ, text אשר מוסיפה טקסט או line שמציירת קו. כמובן נעבור עכשיו לדוגמא:

data CLASS_ANNO;
	length 
		label	$30
		drawspace
		function 	$20;

	function='arrow';
	drawspace='datavalue';
	x2=102.5;
	y2=62.5;
	x1=102.5;
	y1=58;
	output;

	function='text';
	label='Oh Carol';
	drawspace='datavalue';
	anchor='top';
	x1=102.5;
	y1=58;
	width=50;
	output;

	function='line';
	x1=60;
	x2=120;
	y1=55;
	y2=70;
	output;
run;

proc sgplot data=SASHELP.CLASS sganno=CLASS_ANNO;
	scatter x=weight y=height;
run;

מכיוון שמדובר בטבלת SAS רגילה ניתן, כמובן, להשתמש בכל יכולת ה – SAS כדי ליצור את הטבלה הזאת עבור מנגנון ה – annotate:


* Calculating some percentile data;
proc means data=SASHELP.CARS noprint nway;
	var msrp horsepower;
	class origin;
	output out=CARS_MEANS(drop=_type_ _freq_) p5(msrp)=MSRP_P05 p95(msrp)=MSRP_P95 
		p5(horsepower)=HP_P05 p95(horsepower)=HP_P95;
run;

data CARS_ANNO;
	set CARS_MEANS;
	length 
		function	
		linecolor	$8;
	x1=MSRP_P05;
	y1=HP_P05;
	function='polygon';
	x1space='datavalue';
	y1space='datavalue';
	linethickness=3;
	if origin='Asia' then linecolor='blue';
	else if origin='Europe' then linecolor='red';
	else if origin='USA' then linecolor='green';
	else linecolor='black';
	output; * The starting point of our rectangle - lower left;

	x1=MSRP_P05;
	y1=HP_P95;
	function='polycont';
	x1space='datavalue';
	y1space='datavalue';
	output; * Upper left;

	x1=MSRP_P95;
	y1=HP_P95;
	function='polycont';
	x1space='datavalue';
	y1space='datavalue';
	output; * Upper right;

	x1=MSRP_P95;
	y1=HP_P05;
	function='polycont';
	x1space='datavalue';
	y1space='datavalue';
	output; * Lower right;
run;

proc sgplot data=SASHELP.CARS sganno=CARS_ANNO;
	scatter x=msrp y=horsepower/group=origin markerattrs=(symbol=circlefilled);
run;

ה – annotate מאפשר לנו גמישות מדהימה בעת יצירת גרפים אבל, כפי שראיתם הוא דורש קצת עבודה. שימוש מושכל במנגנון הזה יאפשר לנו

ליצור גרפים אפקטיבים יותר המעבירים לקורא את הנקודה שאנחנו רוצים להעביר וזאת כמובן השקעה טובה של זמן.

 

חגי

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Discussion stats
  • 0 replies
  • 275 views
  • 1 like
  • 1 in conversation