ods html image_dpi=300;
title;
data teeth;
input Mammal & $16. v1-v8 @@;
label v1='Top incisors' v2='Bottom incisors'
v3='Top canines' v4='Bottom canines'
v5='Top premolars' v6='Bottom premolars'
v7='Top molars' v8='Bottom molars';
datalines;
Brown Bat 2 3 1 1 3 3 3 3 Mole 3 2 1 0 3 3 3 3
Silver Hair Bat 2 3 1 1 2 3 3 3 Pigmy Bat 2 3 1 1 2 2 3 3
House Bat 2 3 1 1 1 2 3 3 Red Bat 1 3 1 1 2 2 3 3
Pika 2 1 0 0 2 2 3 3 Rabbit 2 1 0 0 3 2 3 3
Beaver 1 1 0 0 2 1 3 3 Groundhog 1 1 0 0 2 1 3 3
Gray Squirrel 1 1 0 0 1 1 3 3 House Mouse 1 1 0 0 0 0 3 3
Porcupine 1 1 0 0 1 1 3 3 Wolf 3 3 1 1 4 4 2 3
Bear 3 3 1 1 4 4 2 3 Raccoon 3 3 1 1 4 4 3 2
Marten 3 3 1 1 4 4 1 2 Weasel 3 3 1 1 3 3 1 2
Wolverine 3 3 1 1 4 4 1 2 Badger 3 3 1 1 3 3 1 2
River Otter 3 3 1 1 4 3 1 2 Sea Otter 3 2 1 1 3 3 1 2
Jaguar 3 3 1 1 3 2 1 1 Cougar 3 3 1 1 3 2 1 1
Fur Seal 3 2 1 1 4 4 1 1 Sea Lion 3 2 1 1 4 4 1 1
Grey Seal 3 2 1 1 3 3 2 2 Elephant Seal 2 1 1 1 4 4 1 1
Reindeer 0 4 1 0 3 3 3 3 Elk 0 4 1 0 3 3 3 3
Deer 0 4 0 0 3 3 3 3 Moose 0 4 0 0 3 3 3 3
;
proc princomp data=teeth out=scores n=2; run;
ods graphics on / height=6in width=6in;
proc sgplot data=scores aspect=1;
scatter y=prin2 x=prin1 / datalabel=mammal;
xaxis min=-4.5 max=3;
yaxis min=-4.5 max=3;
label prin1 = 'Component 1' prin2 = 'Component 2';
run;
proc sgplot data=scores aspect=1 nocycleattrs;
scatter y=prin2 x=prin1 / markerchar=mammal;
xaxis min=-4.5 max=3;
yaxis min=-4.5 max=3;
label prin1 = 'Component 1' prin2 = 'Component 2';
run;
data scores2;
set scores;
if mammal =: 'Beav' then do;
altmammal = mammal;
mammal = ' ';
ay = prin2 - .07;
ax = prin1;
pos = 'bottomright';
end;
if mammal =: 'Grou' then do;
altmammal = mammal;
mammal = ' ';
ay = prin2 + .07;
ax = prin1 - .2;
pos = 'top';
end;
run;
title "Mammals' Teeth";
proc sgplot data=scores2 aspect=1 nocycleattrs noautolegend;
text y=ay x=ax text=altmammal / position=pos;
scatter y=prin2 x=prin1 / datalabel=mammal jitter jitterwidth=10;
xaxis min=-4.5 max=3;
yaxis min=-4.5 max=3;
label prin1 = 'Component 1' prin2 = 'Component 2';
run;
title 'Vital Statistics';
data vital;
input country $ 1-20 Births Deaths;
c = substr(country, 1, 2);
datalines;
USA 15 9
Afghanistan 52 30
Algeria 50 16
Angola 47 23
Argentina 22 10
Australia 16 8
Austria 12 13
Bangladesh 47 19
Belgium 12 12
Brazil 36 10
Bulgaria 17 10
Burma 38 15
Cameroon 42 22
Canada 16 7
Chile 22 7
China 31 11
Taiwan 26 5
Colombia 34 10
Cuba 20 6
Czechoslovakia 19 11
Ecuador 42 11
Egypt 39 13
Ethiopia 48 23
France 14 11
German Dem Rep 12 14
Germany, Fed Rep of 10 12
Ghana 46 14
Greece 16 9
Guatemala 40 14
Hungary 18 12
India 36 15
Indonesia 38 16
Iran 42 12
Iraq 48 14
Italy 14 10
Ivory Coast 48 23
Japan 16 6
Kenya 50 14
Korea, Dem Peo Rep 43 12
Korea, Rep of 26 6
Madagascar 47 22
Malaysia 30 6
Mexico 40 7
Morocco 47 16
Mozambique 45 18
Nepal 46 20
Netherlands 13 8
Nigeria 49 22
Pakistan 44 14
Peru 40 13
Philippines 34 10
Poland 20 9
Portugal 19 10
Rhodesia 48 14
Romania 19 10
Saudi Arabia 49 19
South Africa 36 12
Spain 18 8
Sri Lanka 26 9
Sudan 49 17
Sweden 12 11
Switzerland 12 9
Syria 47 14
Tanzania 47 17
Thailand 34 10
Turkey 34 12
USSR 18 9
Uganda 48 17
United Kingdom 12 12
Upper Volta 50 28
Venezuela 36 6
Vietnam 42 17
Yugoslavia 18 8
Zaire 45 18
;
ods graphics on / height=6.4in width=6.4in;
proc sgplot data=vital noautolegend;
scatter y=deaths x=births / datalabel=country;
run;
data vital2;
set vital;
%macro p(pos, x=0, y=0);
then do;
altcountry = country;
country = ' ';
pos = "&pos" || ' ';
altbirths = births + &x;
altdeaths = deaths + &y;
end;
%mend;
if country eq 'Venezuela' %p(top, x=.7, y=0.25)
if country eq 'Ethiopia' %p(top, y=0.25, x=1)
if country =: 'Ivory' %p(right, x=0.6)
if country eq 'Angola' %p(topleft, x=-0.5)
run;
proc sgplot data=vital2 noautolegend;
scatter y=deaths x=births / datalabel=country;
text y=altdeaths x=altbirths text=altcountry / position=pos;
run;
%let f = attrs=graphdatatext(size=6pt);
proc sgplot data=vital2 noautolegend;
scatter y=deaths x=births / datalabel=country datalabel&f;
text y=altdeaths x=altbirths text=altcountry / position=pos text&f;
run;
data vital3;
set vital;
%macro p(pos, x=0, y=0);
then do;
altcountry = country;
country = ' ';
pos = "&pos" || repeat(' ', 12);
altbirths = births + &x;
altdeaths = deaths + &y;
end;
%mend;
if country =: 'Tai' %p(right, x=.3)
if country =: 'Ban' %p(topleft)
if country =: 'Mal' %p(top, y=.25)
if country =: 'Hun' %p(right, x=.4, y=.1)
if country =: 'Bel' %p(right, x=.4)
if country =: 'Tan' %p(bottomleft)
if country =: 'Vie' or country =: 'Gha' or country =: 'Gua' %p(topleft, y=.1)
if country =: 'Uga' %p(top,y=.1, x=.5)
if country =: 'Sud' %p(right, x=.4)
if country =: 'Fra' %p(topright, x=.4)
if country =: 'Swe' or country =: 'Pak' %p(bottomleft)
if country =: 'Mad' %p(bottom, y=-.1)
if country = 'Australia' %p(top, y=.1, x=-.65)
if country = 'Korea, Rep of' %p(bottom, y=-.15)
run;
%let f = attrs=graphdatatext(size=5.5pt);
proc sgplot data=vital3 noautolegend;
scatter y=deaths x=births / datalabel=country jitter
datalabel&f markerattrs=(size=3pt);
text y=altdeaths x=altbirths text=altcountry / position=pos text&f;
run;
ods html close;