Graphically Speaking

A graph with visual categories

We often say a picture (or graph) is worth a thousand words. So, recursively, this could apply to other text in the graph. I thought it would be interesting to see if we can create a graph with visual categories. Another benefit is that such visual categories are inherently meaningful in all languages.

Here is an interesting graph I saw on the web published by Encyclopedia Britannica on life expectancy for different animals.

SAS Certifications Tutorials and Materials, SAS Certifications Guide, SAS Certifications, SAS Certifications Syllabus

One can see the life expectancy for various animals over the timeline that is wrapped, allowing display of large variations. I used some of this data to create a traditional horizontal bar chart shown below. I did get other images that I used for the five animals. These images are included in the “Images.zip” file linked below.

SAS Certifications Tutorials and Materials, SAS Certifications Guide, SAS Certifications, SAS Certifications Syllabus

I used the same idea as in the graph on top in using pictorial representations for the categories. While I still could not get rid of the numbers on the x-axis, one could say these Arabic numerals are familiar to most people in the world. I wish I could replace the English title text with something appropriate, but did not succeed there. Suggestions are welcome.

The key feature used in the graph above is the SYMBOLIMAGE statement used to define custom symbols from image files. Then, the symbols are inserted in the list of group markers and rendered using a SCATTER plot of the SGPLOT procedure.

title ‘Life Expectancy’;
proc sgplot data=age nowall noborder;
/*–Define marker symbols–*/
symbolimage name=parrot image=”&parrot” / voffset=-0.2;
symbolimage name=elephant image=”&elephant”;
symbolimage name=turtle image=”&turtle”;
symbolimage name=camel image=”&camel”;
symbolimage name=bear image=”&bear”;

styleattrs datasymbols=(bear camel turtle elephant parrot);
scatter x=ximg y=name / group=name markerattrs=(size=60);
hbarparm category=name response=age / baselineattrs=(thickness=0)
dataskin=matte filltype=gradient fillattrs=graphdata1;
xaxis display=(nolabel noline noticks) grid offsetmin=0.07 offsetmax=0.07;
yaxis fitpolicy=none discreteorder=data display=none offsetmin=0.1 offsetmax=0.1;
run;

Full SAS 9.4m2 Code:

%let gpath=’.’;
%let dpi=200;
ods html close;
ods listing gpath=&gpath image_dpi=&dpi;

/*–Data set–*/
data age;
input Name $1-10 Type $11-20 Age;
ximg=-7;
datalines;
Bear Mammal 37
Camel Mammal 43
Turtle Other 44
Elephant Mammal 49
Parrot Bird 66
;
run;

/*–Icon File Names–*/
%let parrot=C:\Parrot_Trans.png;
%let elephant=C:\Elephant_Trans.png;
%let turtle=C:\Turtle_Trans.png;
%let camel=C:\Camel_Trans.png;
%let bear=C:\Bear_Trans.png;

/*–Render plot–*/
ods graphics / reset width=5in height=3in imagename=’Age’;
title ‘Life Expectancy’;
proc sgplot data=age nowall noborder;
/*–Define marker symbols–*/
symbolimage name=parrot image=”&parrot” / voffset=-0.2;
symbolimage name=elephant image=”&elephant”;
symbolimage name=turtle image=”&turtle”;
symbolimage name=camel image=”&camel”;
symbolimage name=bear image=”&bear”;

styleattrs datasymbols=(bear camel turtle elephant parrot);
scatter x=ximg y=name / group=name markerattrs=(size=60);
hbarparm category=name response=age / baselineattrs=(thickness=0)
dataskin=matte filltype=gradient fillattrs=graphdata1;
xaxis display=(nolabel noline noticks) grid offsetmin=0.07 offsetmax=0.07;
yaxis fitpolicy=none discreteorder=data display=none offsetmin=0.1 offsetmax=0.1;
run;

Zip File of images (copy the images in this zip file to “C:\” folder): Images

Advertisements

One thought on “A graph with visual categories

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s